向用户执行除删除操作以外的任何活动时,向后滑动表查看行"Delete Row"选项



我希望能够选择删除某些UITableViewController行。该选项由自定义导航栏下拉菜单BTNavigationDropdownMenu使用标准表查看以下代码的选定行进行切换:

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle { //let object = items[indexPath.row]
    if myPostStatus == true { return UITableViewCellEditingStyle.Delete } else { return UITableViewCellEditingStyle.None }
}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == UITableViewCellEditingStyle.Delete {
       // numbers.removeAtIndex(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
    }
}

一切正常,问题是:- 当我选择了下拉行时,它使表视图能够"删除"。我向左滑动单元格(显示删除按钮),出于某种原因直接触摸下拉菜单以加载不允许删除的数据,该应用程序冻结并显示以下错误。

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.30.14/UITableView.m:1720

如果我手动将单元格滑回其原始位置,然后点击下拉菜单以选择新数据(无法删除),则一切正常,没有任何问题,我可以看到 tableView 单元格中加载的新数据没有提供幻灯片选项删除。

所以,我认为问题是幻灯片打开删除选项。如果有一种方法可以在我触摸导航栏菜单时删除tableView单元格的主动滑动选项向后滑动,我认为一切都应该正常工作。

有人可以帮助我吗?

猜我已经第二次回到你身边了。崩溃的原因可能是因为tableView.endUpdating()方法在tableView.startUpdating之后没有被调用。我不打算详细介绍您的自定义导航控制器。但是我们为您提供的简单方法是隐藏包含您的自定义下拉项的导航栏本身。

    override func setEditing(editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)
        navigationController!.setNavigationBarHidden(true, animated: true)
        self.tableView.setEditing(editing, animated: animated)
}

无论如何,您都可以恢复导航。阅读有关自定义导航栏的信息,以获取更多详细信息(如果需要)。

尝试在点击其他任何地方之前调用 tableView.endEdit。

例如在tableView(tableView willSelectRowAtIndex: NSIndexPath) -> NSIndexPath?

异常可能来自不断变化的 NSIndexPath

最新更新