How do I read a UITableViewCell (subclass)'s height from a NIB?

后端 未结 2 1378
悲&欢浪女
悲&欢浪女 2021-01-18 06:02

I have a UITableViewCell (really a subclass) defined in a NIB. In the NIB I\'ve set the frame height to 183, I also set the \"Row Height\" to 183 and ticked off custom.

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 06:55

    You can use this example code to get cell height from NIB

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        return [[[[NSBundle mainBundle] loadNibNamed:@"ELConvCurListViewCell" owner:self options:nil] objectAtIndex:0] bounds].size.height;
    }
    

    Update: You can get and assign height of NIB once time in the viewDidLoad to the cellHeight variable and in the heightForRowAtIndexPath use return cellHeight

提交回复
热议问题