說實話,UITableView cell自帶的滑動刪除效果,在ios7以前比較醜,但ios扁平化後,這個滑動刪除還是非常好看的。而且實現起來也是非常容易的。
實現這個效果主要是在UITableView協議裏面實現。
如下:
設置可以編輯
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
刪除按鈕點擊
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
//todo
}
}
這裏默認刪除的按鈕爲英文,想要改變成中文,需要再實現一個方法。
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0){
return @" 刪除 ";
}