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?
I want to configure the table cell with 3 field values in each row.
Share
I think the best approach is to create a custom TableViewCell by subclassing the UITableViewCell. Here you will need to give
@propertyand 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.