【问题标题】:TableView swipe-to-delete doesn't workTableView 滑动删除不起作用
【发布时间】:2011-08-11 16:16:20
【问题描述】:

我有一个可编辑的分组 tableView,但滑动删除不起作用。看起来滑动删除应该与 UITableViewCellEditingStyleDelete 一起出现,但对我来说似乎不是。这是我的编辑风格方法:

- (UITableViewCellEditingStyle)tableView:(UITableView *)table editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {        
        if (indexPath.row < [[device_coordinator getChannelList] count]) return UITableViewCellEditingStyleDelete;
        else if (indexPath.row < [[device_coordinator getChannelList] count]+2) return UITableViewCellEditingStyleInsert;
    }
    return UITableViewCellEditingStyleNone;
}

这使表格看起来正确。有些单元格在左侧有插入图标,有些单元格有删除图标,因为它们应该。按下删除图标会出现删除确认按钮。但是滑动不会!

即使我只是从我的 cellForRowAtIndexPath 方法返回空白的、新分配的单元格,它仍然无法工作,因此看来我的单元格中没有任何内容导致问题。同样的问题发生在 4.3 模拟器和我的 iPod touch 2g 上。

【问题讨论】:

    标签: iphone objective-c ios uitableview


    【解决方案1】:

    我认为您的代码是正确的,但如果我理解正确,则存在逻辑错误。您想在编辑模式下滑动删除,这是不可能的。滑动删除仅在用户未处于编辑模式时有效。 所以你只需要通过调用这个方法来隐藏/显示编辑图标。

     -(IBAction)edit:(id)sender//action connected to edit button 
    {
        if(yourTableView.editing) [yourTableView setEditing:NO animated:YES];
        else [yourTableView setEditing:YES animated:YES]; 
    }
    

    然后当单元格旁边没有图标时,滑动删除将起作用。希望这会有所帮助。

    【讨论】:

    • 你是对的!我希望能够同时做到这两点。但至少我知道它现在不起作用的原因。我以为我的应用闹鬼了。
    猜你喜欢
    • 2014-10-08
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 2012-03-17
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    相关资源
    最近更新 更多