我有下面的代码,它将处理 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/