Height of table cells Dynamically + load from .xib

I am using UITableView

several custom cells as well. Each cell has its own height (cells include UICollectionView

, UITableView

and a few more customs UIView

). Moreover, customs boxes (all of them) are loaded from .xib

.

Basically, the cell height should be determined with the model (mvc) or it static

.

In my case, I can figure out the height of the cell after I create each one, ei loadNibNamed:owner:options:

or dequeueReusableCellWithIdentifier:forIndexPath:

(I don't care about reuse, it doesn't), because I need to inflate the contents of the cell.

As far as I know, method calls UITableViewDelegate

, and UITableViewDataSource

are not documented, so I do not need to take into account the order of their call.

How can I determine the height of a cell without instantiating it ? And without Magic numbers

.

+3


source to share


1 answer


You need to calculate the row height in the following UITableViewDelegate methods based on your model.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath

      



If your height calculation is based on the network response, update your data model when you receive the response and call [self.tableView reloadData]

-1


source







All Articles