I have a UITableView of height 400px which I want to fill with either 10 or 11 custom UITableViewCells depending on the data to be displayed. The problem is that depending on how I set the height of each row using my current method, there are gaps between cells or below the bottom cell. I assume this is due to rounding.
This code puts scattered 1px gaps 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 the returns casted to NSIntegers, makes all the cells fit together but leaves a gap of 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 of my cells display with no gaps in between or below the last cell?