I have a tableview where cells are populated from the xib files. There are 2 cell xib files displaying different content in the tableview dynamically.
I want to set the row height for the tableview based on which cell is being populated. I used heightForRowAtIndexPath to set the height of the row depending on the cell xib. Following is the code:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CommentBoxCell *commentBoxCell;
UserCommentCell *userCommentCell;
if ([commentsAndTagsArray count]) {
if (!commentBoxCell){
return commentBoxCell.bounds.size.height;
}
if (!userCommentCell){
return userCommentCell.bounds.size.height;
}
}
//default height of the cell
return 44;
}
Doing this displays nothing in the tableview, just empty cells. Without the heightForRowAtIndexPath, the cells are populated with correct content but with default tableview row height.
How can I set the row height in tableview whose cells are populated from the xib files?
commentBoxCellanduserCommentCellin if? By looking to your code it will be always false as it is not initialised. - Iftikhar Ali AnsaricommentBoxCellanduserCommentCellare bothnil. You need to use[tableView dequeuReuseableCellWithIdentifier:atIndexPath:]. - kientux[tableView dequeuReuseableCellWithIdentifier:atIndexPath:]incellForRowAtIndexPath- s.d.