سؤال

I am trying to create a grouped table view with 3 groups, and each group has cells that are a different height. I've set up 3 prototype cells in my Storyboard with the appropriate heights, and have set up my UITableViewController to return the appropriate heights for each row. However for some reason all of my cells are only 1 pixel tall when they appear on screen.

I've stepped through the code and the correct height and cell is returned for each row. I've also verified that the frame of each cell is correct before it is returned. However calling rectForRowAtIndexPath reveals that the rect for each row is only 1 pixel tall.

This problem goes away entirely when using a constant cell height. In that situation the cells display perfectly, some of them are just too short/tall since they should be variable height.

Any ideas what is going on here? I'd like to undertand how the rect for each row is determined when using heightForRowAtIndexPath.

Code for heightForRowAtIndexPath:

- (NSInteger)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    switch (indexPath.section) {
        case 0:
            return 80.0;
            break;

        case 1:
            return 260.0;
            break;

        case 2:
            return 110.0;
            break;

        case 3:
            return 114.0;
           break;

        default:
            break;
    }
    return 0;
}
هل كانت مفيدة؟

المحلول

You have declared tableView:heightForRowAtIndexPath: to return NSInteger.

That should be CGFloat.

نصائح أخرى

simply to increase the height for row .simply write the method for height for row at indexpath an simply written

if (indexpath.section== 0)

  return 50;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top