下面的代码将处理tableViewCell中的右滑动,当用户权限在具有discussionURL的正确单元上滑动时,它的工作正常,如果用户权限在没有此discussionURL的单元上滑动,则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 []
}
}发布于 2015-10-04 08:16:17
不要返回空操作数组。相反,实现tableView:indexPath:函数,只返回包含讨论URL的单元格的true。如下所示(确保下面的返回语句返回一个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]
}https://stackoverflow.com/questions/32931219
复制相似问题