简体   繁体   English

UITableViewCell问题的自定义高度

[英]Custom height for UITableViewCell issue

When I use the following: 当我使用以下命令时:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [indexPath row] * 20;
}

I have a dynamically populated list and when I use the above, it takes all of my table view cells and only displays one of them. 我有一个动态填充的列表,当我使用上面的列表时,它将使用我所有的table view cells并且仅显示其中一个。

Not sure why? 不知道为什么吗?

This is a MySQL populated list and I never know how many cells there will be. 这是一个由MySQL填充的列表,我不知道会有多少个单元格。 But for testing purposes lets say 2. 但出于测试目的,请说2。

The first row of every section is number 0, so it will never appear (height = 0 * 20 == 0 ). 每个部分的第一行都是数字0,因此它将永远不会出现(高度= 0 * 20 == 0 )。 If you just have one section with 2 rows then you will just see one item. 如果您只有一个包含两行的部分,那么您只会看到一项。 If you have 2 sections, each with 2 rows then you will see 2 rows (the second row in each section). 如果您有2个部分,每个部分有2行,那么您将看到2行(每个部分的第二行)。 If all of your sections have only 1 row then you will never see anything. 如果您所有的部分都只有一行,那么您将永远看不到任何内容。

Change return [indexPath row] * 20; 更改return [indexPath row] * 20; to return 50; return 50; and see what happens. 看看会发生什么。

Then, change to: 然后,更改为:

NSLog(@"Multiply %d by 0, result is %d", [indexPath row], [indexPath row] * 20);
return [indexPath row] * 20;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM