在让tableview可编辑时,添加实现下面3个delegate方法:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}
// 添加这个方法后可以滑动cell,显示delete, ps: editingStyleForRowAtIndexPath 为 UITableViewCellEditingStyleInsert 的时候滑动无效, 需要自行添加[tbView_roster setEditing:YES animated:YES]; 例如下面在 didSelectRowAtIndexPath 中添加 setEditing:animated:
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
// do sth...
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tbView_roster setEditing:YES animated:YES];
}
来源:oschina
链接:https://my.oschina.net/u/237983/blog/193332