我寫了一個 UITableView 擴展,它允許在持有 tableview 后對單元格進行重新排序。
所以 tableView 按預期進入編輯模式,但我想做的是在 viewController 的導航欄中添加一個 Done 按鈕,當 tableView 正在被編輯時,這將在點擊時結束編輯模式。
如何根據 UITableView 擴展中是否正在編輯 tableView 在 vi??ewController 中顯示/隱藏此按鈕?
那是我的擴展:
import UIKit
extension UITableView {
func addLongPressToTableView() {
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(onLongPressGesture(sender:)))
longPress.minimumPressDuration = 0.8 // optional
self.addGestureRecognizer(longPress)
}
@objc func onLongPressGesture(sender: UILongPressGestureRecognizer) {
if (sender.state == .began) {
self.isEditing = true
self.setEditing(true, animated: false)
UIImpactFeedbackGenerator(style: .light).impactOccurred()
}
}
}
// ViewController, hide/show editButtonItem (done button?)
// navigationItem.rightBarButtonItems = [addButton, editButtonItem]
uj5u.com熱心網友回復:
UITableViewDelegate 提供對協調編輯的支持。使用以下兩個委托方法來回應編輯狀態的變化。
func tableView(UITableView, willBeginEditingRowAt: IndexPath)
func tableView(UITableView, didEndEditingRowAt: IndexPath?)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/491371.html
上一篇:Eureka多節點資料不同步問題
