I have a 400-pixel UITableView that I want to populate with either 10 or 11 custom UITableViewCells depending on the data that will be displayed. The problem is that depending on how I set the height of each row using my current method, there are gaps between the cells or the bottom cell. I guess this is due to rounding.
This code places the scattered 1px spaces at the end of some of the cells:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isWednesdaySchedule) {
return (tableView.frame.size.height/11);
}
else {
return (tableView.frame.size.height/10);
}
}
And this code with returned data in NSIntegers makes all the cells fit together, but leaves a few pixels below the bottom cell:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isWednesdaySchedule) {
return (NSInteger)(tableView.frame.size.height/11);
}
else {
return (NSInteger)(tableView.frame.size.height/10);
}
}
How can I fix this so that all my cells are displayed without spaces between or below the last cell?