UITableView does not go into "swipe to delete" mode
My UITableView is linked with my UIViewController instance. The UIViewController instance is the table's UITableViewDelegate and UITableViewDataSource.
Whenever a cell is swiped in the simulator, it does not trigger the "swipe to delete" mode. I tried to provide implementations 开发者_开发技巧for the methods to support "swipe to delete" and table cell editing. None of them get called (none of the NSLogs are logging).
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tableView editingStyleForRowAtIndexPath");
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tableView canEditRowAt...");
return YES;
}
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tableView willBeginEditingRowAtIndexPath: %@", indexPath);
}
- (void)tableView:(UITableView *)tableView willEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tableView willEndEditingRowAtIndexPath: %@", indexPath);
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle {
NSLog(@"tableView commitEditingStyle");
}
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tableView didEndEditingRowAtIndexPath");
}
There must be a simple thing I'm forgetting, but cannot figure out what. Any ideas?
You've implemented tableView:commitEditingStyle:
, but the method you need is tableView:commitEditingStyle:forRowAtIndexPath:
.
That's one of the challenges with implementing protocols. If you incorrectly specify or misspell optional methods, there's no way for the compiler to know.
Here are some tips that might help in the future:
Tip 1: Cut and paste protocol method declarations directly from the documentation to avoid spelling errors and missed arguments.
Tip 2: Create sets of correct protocol methods (with mostly empty bodies) and put them in a code snippet library. Then, always use the stored snippet when adopting a protocol.
精彩评论