在讓tableview可編輯時,添加實現下面3個delegate方法:spa
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{it
return YES;table
}方法
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{im
return UITableViewCellEditingStyleDelete;margin
}word
// 添加這個方法後能夠滑動cell,顯示delete, ps: editingStyleForRowAtIndexPath 爲 UITableViewCellEditingStyleInsert 的時候滑動無效, 須要自行添加[tbView_roster setEditing:YES animated:YES]; 例以下面在 didSelectRowAtIndexPath 中添加 setEditing:animated:tab
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{animate
// do sth...di
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tbView_roster setEditing:YES animated:YES];
}