iOSiOS 开发 iOS开发

UITableViewCell 删除 自定义删除与系统删除共存

2015-08-07  本文已影响864人  _谨

目前需要实现一个功能:


下面开始上关键地方的代码

// 重写该方法,就会出现删除按钮
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 删除操作的代码块...
}

// 修改删除按钮的名称
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

// 点击当前cell响应事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 添加按钮没有隐藏则为单选删除
    if (self.addButton.hidden) {
        LDCellModel *c = self.array[indexPath.row];
        c.check = !c.check;
        [self.tableView reloadData];   // 刷新
    }
}
// 返回特定表格上的编辑样式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.addButton.hidden) {
        return UITableViewCellEditingStyleNone;
    } else {
        return UITableViewCellEditingStyleDelete;
    }
}


实现该功能最关键的方式就是在于

-(UITableViewCellEditingStyle)tableView:(UITableView)tableView editingStyleForRowAtIndexPath:(NSIndexPath )indexPath; 这个方法...

上一篇 下一篇

猜你喜欢

热点阅读