Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set data for static UITableView cells

I have a UITableView that looks like this:

enter image description here

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?

like image 719
8vius Avatar asked Mar 08 '12 17:03

8vius


People also ask

How do I populate UITableView?

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.

How can we use a reusable cell in UITableView?

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.


1 Answers

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.

like image 149
jrturton Avatar answered Sep 28 '22 14:09

jrturton