简体   繁体   中英

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.

Not sure why?

This is a MySQL populated list and I never know how many cells there will be. But for testing purposes lets say 2.

The first row of every section is number 0, so it will never appear (height = 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). If all of your sections have only 1 row then you will never see anything.

Change return [indexPath row] * 20; to 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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