您的位置:首页 > 移动开发 > IOS开发

iOS tableView editCell 删除Cell 置顶Cell NSIndexPath写法

2016-08-26 16:12 411 查看
//正常码tableView 加如下方法:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath{

        //删除按钮

    UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"删除"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){

        

        [_dataArray
removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];

    }];

    

    

    //置顶按钮

    UITableViewRowAction *toTopRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"置顶"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){

        

        NSLog(@"置顶");

        

    

        

        [_dataArray
exchangeObjectAtIndex:indexPath.row
withObjectAtIndex:0];

        

        NSIndexPath *sourceIndexPath = [NSIndexPath
indexPathForRow:indexPath.row
inSection:0];

        NSIndexPath *destinationIndexPath = [NSIndexPath
indexPathForRow:0
inSection:0];

        

        [tableView moveRowAtIndexPath:sourceIndexPath
toIndexPath:destinationIndexPath];

        

        tableView.editing =
NO;

        

    }];

    toTopRowAction.backgroundColor = [UIColor
orangeColor];

    

    //其他按钮

    UITableViewRowAction *otherRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"其他"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){

        NSLog(@"其他");

        [self.tableView
reloadData];

        

    }];

    

    otherRowAction.backgroundColor = [UIColor
lightGrayColor];

    

    //返回按钮数组

    return
@[deleteRowAction, toTopRowAction, otherRowAction];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: