我需要通過從滑動操作“移動”中單擊其中一個單元格來打開 tableView 編輯模式:
滑動操作代碼:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let move = UIContextualAction(style: .normal, title: "Переместить") { (action, view, completionHandler) in
self.turnEditing()
completionHandler(true)
}
move.backgroundColor = UIColor(named: "CalmBlueColor")
let configuration = UISwipeActionsConfiguration(actions: [move])
return configuration
}
turnEditing() 函式:
func turnEditing() {
if tableView.isEditing {
tableView.isEditing = false
} else {
tableView.isEditing = true
}
}
TableView 代表:
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
}
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .none
}
override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false
}
當我按下滑動動作時,它只是關閉,沒有進入編輯模式......這是GIF
是否可以從滑動操作或僅從 barButtonItem IBAction 進入編輯模式?
uj5u.com熱心網友回復:
添加一些延遲
DispatchQueue.main.asyncAfter(deadline: .now() 0.75) {
self.turnEditing()
}
順便說一句,你可以替換這個
if tableView.isEditing {
tableView.isEditing = false
} else {
tableView.isEditing = true
}
和
tableView.isEditing.toggle()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427924.html
標籤:IOS 迅速 合适的视图 uikit uiswipeactions配置
