IPhone: setting static content UITableView

A closer look at Apple's table cells explains how to use the Static Row Content Technique to use Interface Builder to customize the cells in a table.

In my view, I have several cells with different heights. Without using the heightForRowAtIndexPath method heightForRowAtIndexPath everything gets messed up. Should I use this method or can I adjust the height of cells inside IB when I created them there?

Also, when using the "Methods for Static Row Content" from the manual, you still need to use cellForRowAtIndexPath to configure the cells, even if they are created in IB. I would like to customize the full layout of the table using all the cells in IB (drag and drop cells directly into the tableview), is this possible somehow?

+4
source share
2 answers

Although it would be nice if Interface Builder could do all this, it is not. For everything to look right, you must implement heightForRowAtIndexPath: and cellForRowAtIndexPath: To make your task easier, you can create an array and just look at all this (assuming there are not too many rows in the table).

+1
source

Yes, you must implement heightForRowAtIndexPath . However, if you have only static rows, you do not need to implement cellForRowAtIndexPath , because static cells are generated by IB.

To get the cell and its contents (which is probably necessary for calculating the height, for example, labels in different languages ​​can have different lengths, which leads to a different cell size, etc.), you can use the ancestor method, for example:

UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];

-1
source

Source: https://habr.com/ru/post/1309575/


All Articles