UITableViewRowAction表现不可预测

时间:2015-10-04 07:47:36

标签: 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 []
    }
}

1 个答案:

答案 0 :(得分:0)

不要返回空动作数组。而是实现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]
}