2013-03-18 66 views
0

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

回答

7

您必须实施tableView:editingStyleForRowAtIndexPath:委托方法和tableView:commitEditingStyle:forRowAtIndexPath:数据源方法。没有这些,删除将不会出现在单元格中。

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

+0

我终于明白了这一点。我选择了这个答案,因为所有你需要做的就是实现这两个方法,它的工作原理。我已经实现了这两种方法,但删除按钮被隐藏在JASidePanel的中心面板控制器下面...我只需要缩小tableview的宽度就可以了。 – AFraser 2013-03-18 15:05:42

+0

@AFraser - 实际上,您的评论帮助我回答了我的问题自己的问题,因为我的问题非常相似(主视图(在自定义拆分视图控制器中)的右侧被详细视图遮挡)。我肯定会建议把它作为答案,因为你的问题确实提到了JASidePanel控制器。 – Animal451 2014-02-05 08:21:19

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]; 
}