views:

43

answers:

3

I made a UITableViewCell subclass, and now I want that subclass to be "clever". It should align it's contents to the height of the row. But for this, the cell must know what height value was provided for it in this method:

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

However, no matter what value I assign here, my cell's frame is 44 px height at initialization time (default style). Is there any way I can get that value from the cell at initialization time?

+1  A: 

Return the required height of the row from heightForRowAtIndexPath. Also, in your UITableViewCell subclass, make sure you have set the correct frame height for your cell.

Hetal Vora
+1  A: 

You could call heightForRowAtIndexPath yourself to set the frame of the cell if all the height logic is in that method.

Rob Lourens
I see...well that's maybe an option, but i would prefer to put that logic somewhere else than, since this is the delegate method ;-)
dontWatchMyProfile
+1  A: 

I assume that you load data in a background process bacause there is no data at the beginning, it won't call you heightForRowAtIndexPath so it is using the default cell style with 44px and white background.

if you really want to make it looks the same as it has data. you can put some dummy data(empty string) then your heightForRowAtIndexPath will be called.

owen
or if you are sure you have data you can call reloadtabledata or call heightForRowAtIndexPath directly.
owen