Ios UITableVIew滑动轨迹滑动操作未工作时的行配置
新iOS 11Ios UITableVIew滑动轨迹滑动操作未工作时的行配置,ios,swift,uitableview,Ios,Swift,Uitableview,新iOS 11UITableView未调用刷卡操作。委托和数据源对于表来说工作正常 我无法滑动并查看菜单项 下面是我的代码 func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { let contextItem = UIContextualAction(style:
UITableView
未调用刷卡操作。委托
和数据源
对于表来说工作正常
我无法滑动并查看菜单项 下面是我的代码
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let contextItem = UIContextualAction(style: .normal, title: "Leading & .normal") { (contextualAction, view, boolValue) in
print("Leading Action style .normal")
}
let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])
return swipeActions
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let contextItem = UIContextualAction(style: .destructive, title: "Trailing & .destructive") { (contextualAction, view, boolValue) in
print("Trailing Action style .destructive")
}
let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])
return swipeActions
}
我试着打电话到下面,它工作正常
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
}
}
非常感谢任何方向正确的提示。您需要在闭包
boolValue(true)
中将true
传递给UIContextualAction
。否则处理程序将不允许该操作
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let contextItem = UIContextualAction(style: .normal, title: "Leading & .normal") { (contextualAction, view, boolValue) in
boolValue(true) // pass true if you want the handler to allow the action
print("Leading Action style .normal")
}
let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])
return swipeActions
}
代码看起来不错,但您可能缺少类声明中的“UITableViewDelegate”以及viewdidload()部分中的“TableView.delegate=self”。所以它应该看起来像:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
}
}
对于那些使用
UITableViewDiffableDataSource
的用户,您需要对其进行子类化,并覆盖其canEditRowAt
方法
public override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
true
}
你的iOS版本是什么。版本支持是iOS 11。您解决问题了吗?我无法通过“菜单项”滑动并查看菜单项您是指操作吗?是的,基本上我无法滑动UITableViewCell您的tableview上还有其他手势识别器吗?我看代码中没有问题。复制/粘贴时对我有效。@AuRis,因此,如果我们将表的
isEditing
设置为false
,那么我们无法实现单元格的重新排序功能-有办法同时实现这两种功能吗?我的意思是,滑动到删除和单元格重新排序。