I can think of at least two way to do that:
1) Create an empty cell, that will be transparent and whatever height you like, then use this cell for rows at index 1,3,5,7,9,11...
I used this approach before to create custom separator cells, and you can do exactly the same, look at the space between cells like a big transparent separator cell. I posted the code in this question take a look.
2) Second option, is just to use an image with transparent part in the bottom, this way the cells looks like they have a space between them.
To return a different height for the different kind of cells, do:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row % 2 == 0) {
// this is a regular cell
return REGULAR_CELL_HEIGHT;
}
else {
// this is a "space" cell
return SPACE_CELL_HEIGHT;
}
}
You will probably want to disable any selection & user interaction with the "space" cells, so all you need to do is add this to thecellForRowAtIndexPath
method:
if (indexPath.row % 2 == 0) {
cell.userInteractionEnabled = YES;
}
else {
cell.userInteractionEnabled = NO;
}
This will block any user interaction with the cell, if you only want to not show the selection blue color when the user tap on a cell but you still want the didSelectRowAtIndexPath
delegate method to be called, replace the above code with:
if (indexPath.row % 2 == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}