简体   繁体   中英

How to hide the default delete button in the first row of the tableview?

我想隐藏UITableView第一行中的默认删除按钮,对于其余单元格,我想在UITableView显示默认删除按钮。

Implement Table View delegate method - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

something like this:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    BOOL aReturnVal = YES;

    if (indexPath.section == 0 && indexPath.row == 0) {
        aReturnVal = NO;
    }

    return aReturnVal;
}

Implement below table view delegate method to achieve it.

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

    if (indexPath.row == 0) {
        return false;
    }
    return YES;
}

below method also need to implement you can put your logic when row is being delete.

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //put your delete logic here.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM