EXC_BAD_ACCESS in heightForRowAtIndexPath iOS

后端 未结 5 1381
眼角桃花
眼角桃花 2020-11-28 14:27

I\'m working on an application where I have a custom subclass of UITableViewCell. I want to make the cell\'s height dynamic based on the text inside it. I try do do that in

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 14:58

    I had a similar problem and came across, just to share what I do now which works well for me

    CGFloat mycell_height;
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyCell"];
        mycell_height = cell.frame.size.height;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      return mycell_height; //assuming all cells are the same
    }
    

    Hope this helps anyone looking for this and new to iOS programming like me :-)

提交回复
热议问题