TableView,每行2列,iphone/ipad
谁能告诉我如何创建tableview Iphone SDK中有两个colums的单元格 按如下顺序排列:TableView,每行2列,iphone/ipad,iphone,ios,ios4,uitableview,Iphone,Ios,Ios4,Uitableview,谁能告诉我如何创建tableview Iphone SDK中有两个colums的单元格 按如下顺序排列: _____________ | 1 | 2 | |_____|______| | 3 | 4 | |_____|______| 致意在ios UITableView中,您只能有一列/单元格。如果需要更多属性是的,在同一单元格中,您需要通过使用UITableViewCell创建自定义表视图单元格。在interface builder中,可以自定义布局。
_____________
| 1 | 2 |
|_____|______|
| 3 | 4 |
|_____|______|
致意在ios UITableView中,您只能有一列/单元格。如果需要更多属性是的,在同一单元格中,您需要通过使用UITableViewCell创建自定义表视图单元格。在interface builder中,可以自定义布局。教程: 你的问题的具体例子: .h文件:
#import <UIKit/UIKit.h>
@interface MyCell : UITableViewCell {
UIButton * column1;
UIButton * column2;
UILabel* column1_label1;
UILabel* column1_label2;
UILabel* column2_label1;
UILabel* column2_label2;
}
@property (nonatomic,retain) UIButton * column1;
@property (nonatomic,retain) UIButton * column2;
@property (nonatomic,retain) UILabel* column1_label1;
@property (nonatomic,retain) UILabel* column1_label2;
@property (nonatomic,retain) UILabel* column2_label1;
@property (nonatomic,retain) UILabel* column2_label2;
@end
UITableViewController中的用法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
MyCell * mycell2 = ((MyCell*)cell);
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[mycell2.column1 addTarget:self action:@selector(column1Selected:) forControlEvents:UIControlEventTouchUpInside];
[mycell2.column2 addTarget:self action:@selector(column1Selected:) forControlEvents:UIControlEventTouchUpInside];
}
// Configure the cell...
mycell2.column1_label1.text = @"column1_label1";
mycell2.column1_label2.text = @"column1_label2";
mycell2.column1.tag = indexPath.row*2;
mycell2.column2_label1.text = @"column2_label1";
mycell2.column2_label2.text = @"column2_label2";
mycell2.column2.tag = indexPath.row*2 +1;
return cell;
}
- (void) column1Selected: (id) sender
{
UIAlertView *alert = [[ UIAlertView alloc]
initWithTitle: @" Alert"
message: [NSString stringWithFormat: @"button %d",((UIButton *) sender).tag]
delegate: nil
cancelButtonTitle: @" OK"
otherButtonTitles: nil];
[alert show] ;
[alert release];
}
在ios UITableView中,只能有一列/单元格。如果需要更多属性是的,在同一单元格中,您需要通过使用UITableViewCell创建自定义表视图单元格。在interface builder中,可以自定义布局。教程: 你的问题的具体例子: .h文件:
#import <UIKit/UIKit.h>
@interface MyCell : UITableViewCell {
UIButton * column1;
UIButton * column2;
UILabel* column1_label1;
UILabel* column1_label2;
UILabel* column2_label1;
UILabel* column2_label2;
}
@property (nonatomic,retain) UIButton * column1;
@property (nonatomic,retain) UIButton * column2;
@property (nonatomic,retain) UILabel* column1_label1;
@property (nonatomic,retain) UILabel* column1_label2;
@property (nonatomic,retain) UILabel* column2_label1;
@property (nonatomic,retain) UILabel* column2_label2;
@end
UITableViewController中的用法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
MyCell * mycell2 = ((MyCell*)cell);
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[mycell2.column1 addTarget:self action:@selector(column1Selected:) forControlEvents:UIControlEventTouchUpInside];
[mycell2.column2 addTarget:self action:@selector(column1Selected:) forControlEvents:UIControlEventTouchUpInside];
}
// Configure the cell...
mycell2.column1_label1.text = @"column1_label1";
mycell2.column1_label2.text = @"column1_label2";
mycell2.column1.tag = indexPath.row*2;
mycell2.column2_label1.text = @"column2_label1";
mycell2.column2_label2.text = @"column2_label2";
mycell2.column2.tag = indexPath.row*2 +1;
return cell;
}
- (void) column1Selected: (id) sender
{
UIAlertView *alert = [[ UIAlertView alloc]
initWithTitle: @" Alert"
message: [NSString stringWithFormat: @"button %d",((UIButton *) sender).tag]
delegate: nil
cancelButtonTitle: @" OK"
otherButtonTitles: nil];
[alert show] ;
[alert release];
}
在iOS6中,可以使用
如果您需要iOS5支持,那么网格控件将为您提供所需的内容。在iOS6中,您可以使用
如果您需要iOS5支持,那么网格控件将为您提供所需内容。您可以给我们一个示例,说明您希望在单元格中添加什么内容吗?每个单元格将有一张带有两个标签的图片。。这将是对新“新闻”的介绍,用户按下单元格后,它将打开一个包含所有“新闻”的新视图。您能给我们一个示例,您想在单元格中放置什么吗?每个单元格将有一张带有两个标签的图片。。这将是对新“新闻”的介绍,在用户按下单元格后,它将打开一个包含所有“新闻”的新视图。我的问题是,当用户触摸单元格“1”时,它将打开视图_1,当单元格2时,打开视图_2。有任何方法可以做到这一点,只需在界面中一行一列地包含2个假定的列???单元格可以是按钮,而不是标签,并且可以为按钮添加操作处理程序,如下所示:[column1 addTarget:self action:@selector(“whenColumn1Selected:”)forControlEvents:(UIControlEvents)uicontrolEventTouchInside];whenColumn1Selected:whenColumn1Selected:whenColumn1Selected:whenColumn1Selected是一个-(void)whenColumn1Selected{//do somethine when select},如果您在设计中不需要它,您可以关闭原始单元格选择。我将其编辑为单元格1,单元格2作为一个按钮,将警报替换为导航控制器代码,答对了!首先,非常感谢你的回答。。。。问题是每列都有一个带有两个标签的图像,这需要一个视图,对吗??我可以为视图添加一个动作处理程序吗?我的问题是,当用户触摸单元格“1”时,它打开视图1,当单元格2时,打开视图2。有任何方法可以做到这一点,只需在界面中一行一列地包含2个假定的列???单元格可以是按钮,而不是标签,并且可以为按钮添加操作处理程序,如下所示:[column1 addTarget:self action:@selector(“whenColumn1Selected:”)forControlEvents:(UIControlEvents)uicontrolEventTouchInside];whenColumn1Selected:whenColumn1Selected:whenColumn1Selected:whenColumn1Selected是一个-(void)whenColumn1Selected{//do somethine when select},如果您在设计中不需要它,您可以关闭原始单元格选择。我将其编辑为单元格1,单元格2作为一个按钮,将警报替换为导航控制器代码,答对了!首先,非常感谢你的回答。。。。问题是每列都有一个带有两个标签的图像,这需要一个视图,对吗??我可以为视图添加操作处理程序吗???