ios - UITableViewRowAction 的行为不可预测

标签 ios swift swift2

我有下面的代码,它将处理 tableViewCell 中的右侧滑动,当用户在具有discussionURL的正确单元格上向右滑动时,如果用户在没有这个内容的单元格上向右滑动,它工作正常URL 然后 UITableViewRowAction 返回一个空数组。好的,选择没有 URL 的单元格后,我无法选择任何其他 tableViewCell,我什至无法向右滑动。我知道我错过了这里的一些东西。

请帮我解决一下。

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let discussion = UITableViewRowAction(style: .Normal, title: "Discussion") { action, index in
        self.loadTheDiscussionPageInWebViewController(indexPath.section, index: indexPath.row)
    }

    if let _ = self.allDatas[indexPath.section][indexPath.row].discussionUrl {
        print(" BUTTON \(discussion)")

        return [discussion]
    } else {
        print("NO BUTTON")

        return []
    }
}

最佳答案

不要返回空的操作数组。相反,实现 tableView:indexPath: 函数,仅对其中包含讨论 URL 的单元格返回 true。像这样的东西(确保下面的 return 语句返回一个 Bool):

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
     return self.allDatas[indexPath.section][indexPath.row].discussionUrl
}

然后像这样调用您的editActionsForRowAtIndexPath:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let discussion = UITableViewRowAction(style: .Normal, title: "Discussion") { action, index in
    self.loadTheDiscussionPageInWebViewController(indexPath.section, index: indexPath.row)
    return [discussion]
}

关于ios - UITableViewRowAction 的行为不可预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32931219/

相关文章:

ios - 循环遍历核心数据 NSSet 的正确语法

ios - 从其他 NSSet 中减去 NSSet

ios - UICollection View 流布局垂直对齐

ios - 如何快速信任端点 iOS swift

ios - 当按下不同 UITableView 单元格中的另一个播放按钮时,如何自动停止当前播放的音频? - swift

ios - 在 Swift 中更改 UIProgressView(条形)的高度

ios - 在 Swift 2.0 中创建 CMSampleBuffer 的副本

iphone - if/else语句iPhone中的问题

ios - UIImagePickerControllerDelegate didFinishPickingMediaWithInfo 给我一个错误

ios - 在 iOS 上使用 Instagram 验证用户 : specifying redirect_uri