cannyboy cannyboy - 4 months ago 15
iOS Question

Moving the header when in a UITableView's edit mode

I've got a UITableView with custom cells and also a custom header, like so:

--------------------
| Header |
--------------------
| cell |
| cell |
| etc |


Whenever I put it into edit mode, in order to delete cells, it looks like this

--------------------
| Header |
--------------------
- | cell
- | cell
- | etc


As you can see, the table cells are moved right-wards to make room for for the minus icons. However, the header stays in the same position. How would I move the header to the right, to match the cells x-postion below?

Answer

Created a different nib for the edit mode header, and then show it only when editing:

-(UIView *)tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger)section {
// CustomHeader creates the header view
CustomHeader *tableHeader;  
if (self.tableView.editing) 
{
    tableHeader = (CustomHeader *)[CustomHeader headerFromNibNamed:@"CustomHeaderEditMode"];        
} else {
    tableHeader = (CustomHeader *)[CustomHeader headerFromNibNamed:@"CustomHeader"];
}
return tableHeader;
}