您的位置:首页 > 产品设计 > UI/UE

当UITableView 在编辑状态时,点击cell,不调用didSelectedRowAtIndexPath解决办法

2016-11-01 08:12 435 查看
当UITableView 在编辑状态时,点击cell,不调用didSelectedRowAtIndexPath.

问题代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {

    if (self.tableView.editing == YES)  {

        NSLog(@"now in editing mode");

    }

    else {

        NSLog(@"now in normal mode");

    }

}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated  {

    [super setEditing:editing animated:animated];

    // must be called first according to Apple docs

    [self.tableView setEditing:editing animated:animated];

}

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

    // Return NO if you do not want the specified item to be editable.

    return YES;

}

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

    return UITableViewCellEditingStyleNone;

}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath  {

    return NO;

}

以上代码编辑状态下点击cell,无法调用-didSelectedRowAtIndexPath方法打印"now
in editing mode"。

解决方法:

将UITableVIew 的属性 allowsSelectionDuringEdinting 设置为 TRUE,之后就可在编辑模式下,调用点击方法了。

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