I have a UITableView
that looks like this:
In the first cell I display an UIImageView
as you can see, there are also 2 labels. Text is set from code. No problem here.
My problem concerns the bottom 4 cells, I woud like to set the data for them dynamically, the When I'm doing this I can't set the labels and the UIImageView
. I mean setting everything up from cellForRowAtIndexPath
. Can someone explain how I can deal with this case?
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.
For static tables, you can either create an outlet for each individual cell, or refer to them by indexPath - [self.tableView cellForRowAtIndexPath:indexPath];
By the look of your layout the 4 cells are in section 1, rows 0 - 3.
Once you have a pointer to the cell, you can set its textLabel.text and so on just as you would in cellForRowAtIndexPath in a dynamic table view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With