1.單個刪除按鈕
代碼:
//先要設(shè)Cell可編輯
- (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath{
? ? return YES;
}
//定義編輯樣式
- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
? ? return UITableViewCellEditingStyleDelete;
}
//設(shè)置進入編輯狀態(tài)時箭窜,Cell不會縮進
- (BOOL)tableView: (UITableView*)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath*)indexPath {
? ? return NO;
}
//點擊刪除
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
? //根據(jù)需求作刪除數(shù)據(jù)的操作??ps:當(dāng)然要請求接口刪除對應(yīng)的服務(wù)器數(shù)據(jù)
? [self.dataArray removeObjectAtIndex:indexPath.section];
? [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
}
2:測滑多個按鈕
// 自定義左滑顯示編輯按鈕
-(NSArray*)tableView:(UITableView*)tableView editActionsForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?title:@"刪除"handler:^(UITableViewRowAction*_Nonnullaction,NSIndexPath*_NonnullindexPath)? {?
? ? ? ?//作相應(yīng)的操作
? ? ? ?NSLog(@"刪除");
? ? }];
?rowAction.backgroundColor = [UIColor redColor];//設(shè)置背景顏色
?UITableViewRowAction *rowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?title:@"嘿嘿"handler:^(UITableViewRowAction*_Nonnullaction,NSIndexPath*_NonnullindexPath) {
? ? //作相應(yīng)的操作
? ? NSLog(@"嘿嘿");
? }];
? ? rowAction2.backgroundColor = [UIColor blueColor];//設(shè)置背景顏色
?UITableViewRowAction *rowAction3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault? ? ? ? ? ? ? ? ? ? ? ? ?title:@"叼"handler:^(UITableViewRowAction*_Nonnullaction,NSIndexPath*_NonnullindexPath) {
? ? ? //作相應(yīng)的操作? ?
? ? ? NSLog(@"叼");
}];
? ? rowAction3.backgroundColor = [UIColor blackColor];//設(shè)置背景顏色
? ? NSArray*arr =@[rowAction,rowAction2,rowAction3];
? ? return? arr;
}
3.總結(jié)
自帶的測滑刪除已經(jīng)很6穴张。