Reputation: 1435
I want to configure the table cell with 3 field values in each row. I have three database fields like Amount
, Note
, and DueOn
. I want to configure the cell values so that Amount
is a title, and DueOn
and Note
are values. How is this possible?
Upvotes: 1
Views: 322
Reputation: 1922
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.text = [NSString stringWithFormat:@"Amount: %@", amount];
cell.detailedTextLabel.numberOfLines = 2;
cell.detailedTextLabel.text = [NSString stringWithFormat@"Note:%@\nDueOn:%@", note, dueOn];
Upvotes: 1
Reputation: 19469
I think the best approach is to create a custom TableViewCell by subclassing the UITableViewCell. Here you will need to give @property
and synthesize the labels which you want to access and assign values to.
Then what you can do is just create a object of the custom cell in your tableView:cellForRowAtIndexPath:
and then just assign the values to the labels which are in custom cell.
Also I would advise you to add the labels into the custom cell class programmatically and not through XIB as this would save you some amount of the complexities.
ADVANTAGES OF THIS APPROACH:
1) This approach simplifies the complexity as this would enable you to make future changes and updates related to custom cell easier to make as you will have to make changes only at one place.
2) In comparison to an approach where you add the labels on the fly, in cellForRowAtIndexPath:
, also the problem of dequeuing and problems regarding duplication of labels everytime the cell is created doesn't occur in this case as whole set of labels are managed in an object and you just need to reuse the cell and other things are managed automatically.
Hope this helps.
Upvotes: 1
Reputation: 19418
you can refer below links to create custom cells
http://www.e-string.com/content/custom-uitableviewcells-interface-builder
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Upvotes: 1
Reputation: 1814
you have to create custom table cell.
Just search for custom table cell on google and you can get this.
Upvotes: 2