【发布时间】:2023-04-01 21:15:02
【问题描述】:
在 iOS 11 上,单元格编辑操作或滑动操作(仅适用于 iOS 11)显示在部分标题的顶部,如果表格视图样式设置为普通(未分组)。这似乎是默认功能,如果这是系统错误或者我的实现错误,我会徘徊。
我实现了一个演示应用程序,使用默认表格视图实现以及标题和编辑操作行的以下功能:
标题标题:
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Section \(section)"
}
编辑行的操作:
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let firstAction = UITableViewRowAction(style: .normal, title: "Action1", handler: {_,_ in })
let secondAction = UITableViewRowAction(style: .destructive, title: "Action2", handler: {_,_ in })
return [firstAction, secondAction]
}
尾随滑动操作(仅适用于 iOS 11 的新实现):
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action1 = UIContextualAction(style: .normal, title: "Action1", handler: {_,_,_ in })
let action2 = UIContextualAction(style: .destructive, title: "Action2", handler: {_,_,_ in })
return UISwipeActionsConfiguration(actions: [action1, action2])
}
这只发生在 iOS 11 上。我曾尝试交替使用上述两种方法,但我得到了相同的结果。
你知道我应该如何解决这个问题吗?这是 iOS 11 系统错误吗?
【问题讨论】:
-
看起来它只发生在 iOS 11.4 上。在那种情况下至少对我来说。
-
我已经在其他版本的 iOS 上测试过,对我来说也发生在 11.2.2 上,所以我认为这是 iOS 11 的一般问题
-
是的,刚刚在 iOS 11.3 上测试过,你是对的 @frozencure 似乎只有 iOS 11
-
可能我们做错了什么,但到目前为止,这对我来说似乎是一个系统错误。同样的事情似乎在 iOS 9 和 iOS 10 中运行良好
-
我自己也遇到了这个问题 :( 在 iOS 9、10 但不是 11 上工作。有解决方法的想法吗?
标签: ios swift uitableview cocoa-touch ios11