IPhone: changing height of UITableViewCell coming from NIB
I have a custom UITableViewCells UITableView that looks like this:
[ CELL 0
[ description ]
[ dynamic content type 1 ]
[ dynamic content type 2 ]
[ dynamic content type 3 ]
]
[ CELL 1
[ description ]
[ dynamic content type 1 ]
[ dynamic content type 3 ]
]
[ CELL 2
[ description ]
[ dynamic content type 2 ]
]
[ ... and so on ... ]
Since the [description] part is already quite complex, I decided to use the Interface Builder to create it and add the code cellForRowAtIndexPath
to cellForRowAtIndexPath
c [cell addSubview:...]
. My problem is that I have set the default height for my custom UITableViewCell in the Interface Builder, but when I add my [dynamic content] (which can range from 0 to 3) I have different cells with different heights.
Of course one needs to calculate the total height and change the return value to heightForRowAtIndexPath
, but how do I change the height value of my actual one cell
(which was loaded from a fixed height nib file)
a source to share
You want to compute and return the value in:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
It should be noted that this will be called for every line in your view at startup, so be careful with what you create to calculate the size.
Another option, which might be more standard in implementation, is to make a grouped TableView widget and have what you call a cell, a section here, and then each row either a description or dynamic content. This is how I would do it if your ascii drawing was my design spec, but I assume you have more stuff to run from.
a source to share