I’m trying to calculate the necessary height for a cell in a tableview based on what the contents are going to be. This is in - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath.
However, sometimes sizeWithFont is returning 0. I can’t figure out how this is possible, because all the parameters are hardcoded except for one, and I can see that that parameter isn’t changing.
NSString *address = [properties objectAtIndex:1];
CGFloat calculatedSize = [address sizeWithFont:[[UIFont alloc] fontWithSize:15.f] constrainedToSize:CGSizeMake(207.f, 100.f) lineBreakMode:UILineBreakModeWordWrap].height;
NSLog(@"Calculated size for %@: %f", address, calculatedSize);
calculatedSize += 19.f;
return calculatedSize;
This is the output if I go try this several times by going back and forth to the view several times:
Calculated size for 1234 Fake St: 0.000000
Calculated size for 1234 Fake St: 0.000000
Calculated size for 1234 Fake St: 0.000000
Calculated size for 1234 Fake St: 38.000000
Calculated size for 1234 Fake St: 0.000000
Calculated size for 1234 Fake St: 38.000000
Replace:
with: