how to get a UITableView row height to auto-size to the size of the UITableViewCell?

前端 未结 5 843
梦谈多话
梦谈多话 2020-12-23 17:24

How to get a UITableView row height to auto-size to the size of the UITableViewCell?

So assuming I\'m creating the UITableViewCell in Interface Builder, and it hei

5条回答
  •  情深已故
    2020-12-23 18:28

    self.tableView.estimatedRowHeight = 65.0; // Estimate the height you want
    self.tableView.rowHeight = UITableViewAutomaticDimension; // auto change heights for multiple lines cells.
    

    When implement UITableViewDataSource required method:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        cell.textLabel.text = [self.todoArray objectAtIndex:indexPath.row];
        cell.textLabel.numberOfLines = 0; // allow multiple lines showing up
    
        return cell;
    }
    

提交回复
热议问题