tableview:commitEditingStyle:forRowAtIndexPath如何在某些单元格上显示停止删除按钮

C.J*_*hns 3 iphone uitableview ios swipe-gesture

我想知道是否有任何方法阻止"清除"按钮出现在特定的uitableviewcell上并让它出现在另一个上?

我已经设置了一个客户uitableview单元格,其中有一个按钮,我正在使用

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
Run Code Online (Sandbox Code Playgroud)

方法..我想知道你是否可以在用户滑动删除时停止在几个uitableviewcells之一上显示的按钮?

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"Clear";
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) 
    {
        //cell fade - notifies the user that they are edited their cell
        NSArray *rowArray = [NSArray arrayWithObject:indexPath];
        [self.tableView reloadRowsAtIndexPaths:rowArray withRowAnimation:UITableViewRowAnimationFade];

        if (indexPath.row == 0) 
        {

            manufactureSearchObjectString = @"empty";
            [self.tableView reloadData]; //reloads the tabel with new value
            manufactureResultIndexPath = nil; //removes tick from subview

        }
        else if (indexPath.row == 1) 
        {

        }
        else if (indexPath.row == 2) 
        {

        }
        else if (indexPath.row == 3)
        {
            keyTypeSearchObjectString = @"empty";
            [self.tableView reloadData]; //reloads the tabel with new value
            keyTypeResultIndexPath = nil; //removes tick from subview

        }
    }
    else if (indexPath.section == 1) 
    {
        if (indexPath == 0) 
        {
            //can I stop the "clear" button from showing in here?
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

更具体一点,我想阻止这种情况发生 在此输入图像描述

Nar*_*ana 6

使用以下方法

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
            if (indexPath.section == 1) 
            {
              if (indexPath.row == 0) 
              {
                 return NO;// you can  stop the "clear" button from showing in here?
              }
              else
                return YES;
            }
          else
            return YES;


    }
Run Code Online (Sandbox Code Playgroud)