C.Johns
C.Johns

Reputation: 10245

dynamic uitableviewcell height according to custom cell height

I am wondering, is there a way to read the height of the custom tableview cell you are going to use in your uitableviewcell which you can then say to your uitableviewcell be this ---> height?

Upvotes: 0

Views: 450

Answers (2)

lnafziger
lnafziger

Reputation: 25740

No, the height that you set in the xib/storyboard is for display purposes only and doesn't transfer over to code.

The only way to change the height is from your custom subclass, by overriding tableView:heightForRowAtIndexPath:.

If you have a lot of different heights, you could always subclass UITableViewCell and add a height property which tableView:heightForRowAtIndexPath: uses when it sees your subclass. Then, in your storyboard, select your cell, go to the identity inspector, and add a User Defined Runtime Attribute for height with the value that you need.

Upvotes: 0

munibsiddiqui
munibsiddiqui

Reputation: 435

I am not fully understand your question but do you want to set the height for each custom cell ? If yes then you can do it by :

Let say I have custom cell at index 0 rest are my default cells or can be custom cell as well .

- (CGFloat)tableView:(UITableView *)_tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 ) {
       return 105.0;
    }else {
        return 80.0;
    }
}

Upvotes: 2

Related Questions