標籤:com win code mat nbsp default 代理 cte actions
局部重新整理方法
添加資料
NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
刪除資料
NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
更新資料(沒有添加和刪除資料,僅僅是修改已經存在的資料)
NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView relaodRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
左滑出現刪除按鈕
左滑出現N個按鈕
需要實現tableView的代理方法只要實現了這個方法,左滑出現按鈕的功能就有了(一旦左滑出現了N個按鈕,tableView就進入了編輯模式, tableView.editing = YES)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } // 左滑cell時出現什麼按鈕 - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"關注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了關注"); // 收回左滑出現的按鈕(退出編輯模式) tableView.editing = NO; }]; UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { [self.wineArray removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }]; return @[action1, action0];}
進入編輯模式
// self.tabelView.editing = YES;[self.tableView setEditing:YES animated:YES];// 預設情況下,進入編輯模式時,左邊會出現一排紅色的“減號”按鈕
// 編輯模式的時候可以多選self.tableView.allowsMultipleSelectionDuringEditing = YES;// 進入編輯模式[self.tableView setEditing:YES animated:YES];// 獲得選中的所有行self.tableView.indexPathsForSelectedRows;
iosTableView 局部全部重新整理以及刪除編輯操作