解决使用editActionsForRowAtIndexPath添加删除按钮,6Plus不响应的办法

来源:互联网 发布:蒸汽朋克淘宝 编辑:程序博客网 时间:2024/05/15 13:49

在真机测试时,碰上一个问题,在删除cell时,模拟器上删除按钮可以出来,但是到真机上面就不行,不响应,找到一个麻烦的解决办法,就是把删除cell的两个方法全部写上(上一个博客有一个删除cell的方法,是iOS8以后新增的)上代码:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    returnYES;

}


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    returnUITableViewCellEditingStyleDelete;//删除cell

}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    

    if (editingStyle ==UITableViewCellEditingStyleDelete) {

        

        [dataArrayremoveObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath, nil]withRowAnimation:UITableViewRowAnimationNone];

    }

}

-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{


    UITableViewRowAction *rowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"删除"handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {


            

    }];


//    rowActionSec.backgroundColor = [UIColor colorWithHexString:@"f38202"];

    rowAction.backgroundColor = [UIColorpurpleColor];


    UITableViewRowAction *rowaction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"置顶"handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {

        

    }];

    rowaction.backgroundColor = [UIColorgrayColor];

    NSArray *arr =@[rowAction,rowaction];

    return arr;

}


0 0
原创粉丝点击