iphone - TableView :commitEditingStyle:forRowAtIndexPath how to stop delete button from showing on some cells

标签 iphone ios uitableview swipe-gesture

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

我已经设置了一个自定义的 uitableview 单元格,里面有一个按钮,我正在使用

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

方法.. 我想知道您是否可以在用户滑动删除时停止出现在几个 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?
        }
    }
}

更具体一点,我想阻止这种情况发生 enter image description here

最佳答案

使用下面的方法

- (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;


    }

关于iphone - TableView :commitEditingStyle:forRowAtIndexPath how to stop delete button from showing on some cells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7669863/

相关文章:

ios - 弹出 UIViewController 时奇怪的 Tabbar 动画

iphone - 将数据存储在核心数据中

iphone - 在 iOS 中使用 openAL 预加载音频文件的好方法

ios - 面试 - 在中心定位和重置球

iphone - 如何在 iPhone 应用程序中使用 FB Graph 搜索 API

iOS:使用 UITextField 子类检测空 UITextField 中的退格键

按下按钮时,IOS Swift 完成功能

ios - 在 UITableView 单元格中设置按钮边框时出现 fatal error

ios - UITableView 单元格标题传输到另一个 View 上的 Uitextfield

ios - 注册和出列特定类型的 UITableViewCell