-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if([tableView.somethingMagicalHereThatAllowsMeKnowWhichCellItIs isEqualToString:@"CellType"]){
return 50;
}
return 25;}
I have tableView with multiple cells of different types, and I want to style them accordingly, but the problem is that I don’t know which type it is when it comes in. I can’t use indexPath because the cells are in no specific order. Is there a way to show the id?
What I usually do is remove the “what goes in which table view cell” from
-tableView:cellForRowAtIndexPath:and put it in a separate method. How I name this depends on what I’m trying to achieve. One typical scenario is that each cell represents an object. In that case, I define a method like this:Then, in both
-tableView:cellForRowAtIndexPath:and-tableView:heightForRowAtIndexPath:, I call that method to find out which object corresponds to that cell, then either create the cell or set its height accordingly.