开发者

Configuring the table cell

I want to configure the table cell with 3 field values in each row. I have three database fields li开发者_开发技巧ke 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?


you have to create custom table cell.
Just search for custom table cell on google and you can get this.


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.


you can refer below links to create custom cells

  1. http://www.e-string.com/content/custom-uitableviewcells-interface-builder

  2. http://blog.webscale.co.in/?p=284

  3. http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜