iOS tableView editCell 刪除Cell 置頂Cell NSIndexPath寫法
//正常碼tableView 加如下方法:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
//刪除按鈕
UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"刪除"handler:^(UITableViewRowAction * _Nonnull action,
[_dataArrayremoveObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];
}];
//置頂按鈕
UITableViewRowAction *toTopRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefault
NSLog(@"置頂");
[_dataArrayexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:0];
NSIndexPath *sourceIndexPath = [NSIndexPathindexPathForRow:indexPath.rowinSection:0];
NSIndexPath *destinationIndexPath = [
[tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
tableView.editing = NO;
}];
toTopRowAction.backgroundColor = [UIColororangeColor];
//其他按鈕
UITableViewRowAction *otherRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"其他"handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath){
NSLog(@"其他");
[self.tableViewreloadData];
}];
otherRowAction.backgroundColor = [UIColorlightGrayColor];
//返回按鈕陣列
return@[deleteRowAction, toTopRowAction, otherRowAction];
}