首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewRowAction行为不可预测

UITableViewRowAction行为不可预测
EN

Stack Overflow用户
提问于 2015-10-04 07:47:36
回答 1查看 124关注 0票数 0

下面的代码将处理tableViewCell中的右滑动,当用户权限在具有discussionURL的正确单元上滑动时,它的工作正常,如果用户权限在没有此discussionURL的单元上滑动,则UITableViewRowAction返回一个空数组。好的,在选择了一个没有URL的单元格之后,我无法选择任何其他的tableViewCell,我甚至不能正确地滑动。我知道我错过了一些东西。

请帮我弄清楚。

代码语言:javascript
复制
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 []
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-04 08:16:17

不要返回空操作数组。相反,实现tableView:indexPath:函数,只返回包含讨论URL的单元格的true。如下所示(确保下面的返回语句返回一个Bool):

代码语言:javascript
复制
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
     return self.allDatas[indexPath.section][indexPath.row].discussionUrl
}

然后这样调用您的editActionsForRowAtIndexPath

代码语言:javascript
复制
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]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32931219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档