首页 文章

UITableViewCell删除按钮没有出现

提问于
浏览
0

我有一个UITableview,我放在一个JASidePanel控制器(https://github.com/gotosleep/JASidePanels)我已经在我的init方法中设置了委托和数据源,我已经实现了canEditRowAtIndexPath方法,当我在tableview单元格上滑动时它们被调用但是没有任何东西在视觉上发生 . 我已经查看了其他问题并已实现了所有建议,但无法显示删除按钮 . 有谁知道会导致这种行为的原因是什么?

3 回答

  • 7

    您必须实现 tableView:editingStyleForRowAtIndexPath: 委托方法和 tableView:commitEditingStyle:forRowAtIndexPath: 数据源方法 . 如果没有这些,则不会为单元格显示删除 .

    我假设您从 tableView:canEditRowAtIndexPath: 数据源方法返回 YES (至少对于相应的行) .

  • 1

    您是否尝试过此类自己的删除单元格的方法?

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
       if (UITableViewCellEditingStyleDelete) {
          int k = [[tempArray objectAtIndex:indexPath.row] intValue];
    
          //Remove object from index 'k'.
       }
    }
    

    它可能对你有所帮助 .

    谢谢 .

  • 0

    在滑动TableViewCell时执行UITableView的删除操作 . 我们必须实施以下三种方法: -

    此方法将在滑动TableViewCell时显示删除按钮 .

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    
      NSUInteger row = [indexPath row];
      NSUInteger count = [posts count];
    
      if (row < count) {
        return UITableViewCellEditingStyleDelete;
      } else {
        return UITableViewCellEditingStyleNone;
      }
    }
    

    当用户在滑动TableViewCell时删除一行时,将调用此方法,并且在点击删除按钮时将删除滑动的行 .

    - (void)tableView:(UITableView *)tableView 
            commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
            forRowAtIndexPath:(NSIndexPath *)indexPath {
    
      NSUInteger row = [indexPath row];
      NSUInteger count = [posts count];
    
      if (row < count) {
        [posts removeObjectAtIndex:row];
      }
    }
    

    最后调用此方法以在删除行后更新表视图 .

    - (void)tableView:(UITableView *)tableView 
                       didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    
      [self updateViewTitle];
      [tableView reloadData];
    }
    

相关问题