Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In ios UITableView you can only have one column/cell. If you want more propertyes, in a same cell you need to create a custom table view cell by subcalssing UITableViewCell. In interface builder you can customize the layout. TUTORIAL: <a href="http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/" rel="nofollow noreferrer">http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/</a></p> <p>Concrete example for your problem:</p> <p>the .h file:</p> <pre><code> #import &lt;UIKit/UIKit.h&gt; @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 </code></pre> <p>the .m file:</p> <pre><code>#import "MyCell.h" @implementation MyCell @synthesize column1,column1_label1,column1_label2,column2,column2_label1,column2_label2; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { column1 = [UIButton buttonWithType: UIButtonTypeCustom]; column1.tag = 1; column1.autoresizingMask = 292; column1.backgroundColor = [UIColor redColor]; column1.frame = CGRectMake(0, 0, self.contentView.bounds.size.width/2, self.contentView.bounds.size.height); column1_label1 = [[UILabel alloc] initWithFrame: CGRectMake(column1.bounds.size.width*1/5, 0, column1.bounds.size.width*4/5, column1.bounds.size.height/2)]; column1_label1.backgroundColor = [UIColor redColor]; [column1 addSubview:column1_label1]; column1_label2 = [[UILabel alloc] initWithFrame: CGRectMake(column1.bounds.size.width*1/5, column1.bounds.size.height/2, column1.bounds.size.width*4/5, column1.bounds.size.height/2)]; column1_label2.backgroundColor = [UIColor greenColor]; [column1 addSubview:column1_label2]; [self.contentView addSubview: column1]; column2 = [UIButton buttonWithType: UIButtonTypeCustom]; column2.tag = 2; column2.autoresizingMask = 292; column2.backgroundColor = [UIColor greenColor]; column2.frame = CGRectMake(self.contentView.bounds.size.width/2, 0, self.contentView.bounds.size.width/2, self.contentView.bounds.size.height); column2_label1 = [[UILabel alloc] initWithFrame: CGRectMake(column2.bounds.size.width*1/5, 0, column2.bounds.size.width*4/5, column2.bounds.size.height/2)]; column2_label1.backgroundColor = [UIColor redColor]; [column2 addSubview:column2_label1]; column2_label2 = [[UILabel alloc] initWithFrame: CGRectMake(column2.bounds.size.width*1/5, column2.bounds.size.height/2, column2.bounds.size.width*4/5, column2.bounds.size.height/2)]; column2_label2.backgroundColor = [UIColor greenColor]; [column2 addSubview:column2_label2]; [self.contentView addSubview: column2]; } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)dealloc { [super dealloc]; } @end </code></pre> <p>the usage in UITableViewController:</p> <pre><code> - (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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload