Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableview cells height is not working in a empty table?

Tags:

I'm using below code to create a larger and more clean look on a plain (not grouped) UITableView. It's working fine unless i have a empty table then the cell's height sets to normal height. I have the standard Separatorstyle (the gray lines) so it looks rly bad if it's empty.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    return 75;
}

Any idea how to fix this?

EDIT:

Found an even better solution where i dont even display the lines if the table is "Empty" and displays guide text instead.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([dataArray count] == 0) {
        [theTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [pleaseAddStuffText setHidden:NO];
    } else {
        [theTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
        [pleaseAddStuffText setHidden:YES];
    }
    return [dataArray count];
}
like image 749
David Avatar asked Aug 27 '11 13:08

David


1 Answers

You should be able to force a row height at all times by setting rowHeight, even if the row count is 0.

self.tableView.rowHeight = 75.0;

You can also set it in IB.

heightForRowAtIndexPath seems to only be called if a cell is being set up in cellForRowAtIndexPath, whereas this is a property of the tableview and is always present.

like image 89
mjisrawi Avatar answered Oct 21 '22 20:10

mjisrawi