Reputation: 3350
I have two custom UITableViewCell
in my table view, that I can't resize properly. The problem is that in IB there is a row height option for the table view, that sets the same height for both cells. I can't just edit the height of the cells in IB, somewhy it doesn't works, the table view's row height overwrites it. I'm using static heights so I tried to set it based on the cell's type, but can't make it work. Is it possible that just my if statement is wrong or I done the whole thing wrong?
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath {
InboxCellTableViewCell *cellMessage = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
InboxCell2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
if(cell) {
[cellMessage layoutIfNeeded];
return 200;
} else {
[cell layoutIfNeeded];
return 155;
}
}
Upvotes: 1
Views: 801
Reputation: 5380
You definitely can do this, and you will do it in -heightForRowAtIndexPath as you suspect.
Instead of attempting to load the cell as you are doing, you should instead use the IndexPath to determine what type of cell is there and then return the proper height for that cell type.
In your cellForRowAtIndexPath method you must have some logic that is already determining the cell type for a given IndexPath, as you return a varying type of Cell from that method already? That same logic can be used to return the appropriate height in the heightForRowAtIndexPath method.
Upvotes: 2