Reputation: 1318
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];
}
Upvotes: 21
Views: 4370
Reputation: 26548
I'm using Auto Layout inside the cells so I need automatic row height. But I also want the cell size to be bigger than the standard 44 points height when the table is empty. What I ended up doing is set the row height and estimate to 124 in the storyboard file and implement the tableView:heightForRowAtIndexPath:
method to return UITableViewAutomaticDimension
:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Upvotes: 0
Reputation: 11053
What dou you mean by empty table? If the complete table is empty then the returned number of section for the table is empty. That means nothing will be shown on the table at all.
If you however have an empty table line = table cell, then you should make sure that the cell at indexpath
returns something where you just need to put empty values. Then you will have an empty line between your other lines in your table.
What exactly is/should be empty?
Upvotes: -1
Reputation: 7936
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.
Upvotes: 39