实现下面方法,可以在tableView的cell上滑动时,拉出删除按钮
1
2
3
4
|
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return
UITableViewCellEditingStyleDelete;
}
|
在 UITableView 的 delegate 里实现下面这个方法,可以修改删除按钮的文字
1
2
3
4
|
- (NSString*)tableView:(UITableView*)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath {
return
@
"删除"
;
}
|
实现下面这个方法,在滑出删除按钮点击后,执行相应的操作
1
2
3
4
5
6
7
8
9
|
- (
void
)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if
(editingStyle == UITableViewCellEditingStyleDelete) {
NSUInteger row = [indexPath row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
// 数据源也要相应删除一项
}
}
|