I have a grouped tableview. Each section has three rows. I need to be able to delete one section at a time. Using the standard edit mode, I can make it work. However, the delete icon shows up to the left of each cell, not just the first row in each section.
Is there a way to suppress the little spinner icon for all rows except the first?
I am hoping there is an easy way开发者_如何学C to do this without subclassing.
Here is a screenshot to help visualize it: http://picasaweb.google.com/lh/photo/ll-EJY5ACw7oqHH1xKBQ8w?feat=directlink
Try this:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0) {
return UITableViewCellEditingStyleDelete;
} else {
return UITableViewCellEditingStyleNone;
}
}
Instead of deleting rows, make a parent UIView
that contains a UILabel
and custom UIButton
as subviews. Set this parent view as the section header view.
The button should be wired up to trigger a method that deletes rows by, for example, flipping a BOOL
state flag for that section and then reloading the table:
- (void) deleteMySection:(id)sender {
self.showMySection = NO;
[tableView reloadData];
}
Your -numberOfSectionsInTableView:
delegate method will accordingly adjust its output depending on the state of this boolean flag, e.g.
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tv {
return ((showMySection) ? numberOfSections : numberOfSections - 1);
}
精彩评论