ferris ferris - 1 month ago 8
Objective-C Question

Swipe to delete cell causes tableViewHeader to move with cell

I have encountered a strange bug with my

tableViewHeader
on my
UITableView
in iOS 8. When swiping on a cell to reveal the delete button (standard iOS swipe-to-delete), it moves the
tableViewHeader
along with the cell that is being swiped. As I swipe the cell, the header moves in the same way that the cell being swiped does. No other cells in the table view are moved, only the header and whatever cell is being swiped. I have tested this on iOS 7 haven't encountered the problem. To me, this seems like a bug with
tableViewHeader
in iOS 8, being that it only occurs in this version and seems like something that should never occur. I see no reason for the header to ever be included in swipe-to-delete.

Below is just a mockup. Swipe-to-delete within the app is default iOS, nothing custom.

Below is just a mockup. Swipe-to-delete within the app is default iOS, nothing custom.

Answer

This was caused because I was using a UITableViewCell as the header for the table. To solve the swiping issue, instead of using tableView.tableHeaderView = cell, I use the following:

UIView *cellView = [[UIView alloc] init];
[cellView addSubview:cell];
tableView.tableHeaderView = cellView

I don't know why this solves the problem, especially being that it worked on iOS 7, but it seems to solve the problem.

Make sure to add all view to the cells view, as supposed to the cells contentView, otherwise the buttons will not be responsive.

Works:

[cell addSubview:view]; or [self addSubview:view];

Doesn't work:

[cell.contentView addSubview:view] or [self.contentView addSubview:view]