内容に基づいて、テーブルビューのセルに必要な高さを計算しようとしています。これは にあり- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
ます。
ただし、sizeWithFont が 0 を返す場合があります。1 つを除いてすべてのパラメーターがハードコードされているため、これがどのように可能であるかがわかりません。そのパラメーターは変更されていないことがわかります。
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;
これは、ビューを何度か行ったり来たりして、これを数回試した場合の出力です。
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