我需要在长按后更改leftBarButtonItem,我在TabBarController中设置了leftBarButtonItem,并在UsersController中设置了长按操作,如何才能做到这一点?
选项卡栏控制器:
class TabViewController: TabmanViewController {
private var viewControllers = [ DashboardController(),ClientsController(), UsersController() ]
var viewModel = TabBarViewModel()
var coordinator: TabBarCoordinator?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Dashboard"
let rightItem = UIImage(named: "userIcon")
let leftItem = UIImage(named: "backMenuButton")
let rightButton = UIBarButtonItem(image: rightItem, style: .done, target: self, action: #selector(rightAction))
let leftButton = UIBarButtonItem(image: leftItem, style: .done, target: self, action: #selector(leftAction))
self.navigationItem.rightBarButtonItem = rightButton
self.navigationItem.leftBarButtonItem = leftButton
用户控制器长按:
@objc func handleLongPress(longPressGesture: UILongPressGestureRecognizer) {
let longPress = longPressGesture.location(in: self.usersTableView)
usersTableView.allowsMultipleSelection = true
let indexPath = self.usersTableView.indexPathForRow(at: longPress)
UINotificationFeedbackGenerator().notificationOccurred(.success)
if indexPath == nil {
print("Long press on table view, not row.")
}
else if (longPressGesture.state == UIGestureRecognizer.State.began) {
print("Long press on row, at \(indexPath!.row)")
if !previousIndexPath.isEmpty {
}
}
if let selectedIndexPath = self.usersTableView.indexPathForSelectedRow {
self.usersTableView.deselectRow(at: selectedIndexPath, animated: true)
}
userLabel.text = "Select"
usersNumber.text = "0"
plusButton.isHidden = true
}
1条答案
按热度按时间biswetbf1#
您必须在更新图像后重置导航leftBarButtonItem。
S1:在ViewController中声明变量。
S2:设置初始图像并配置动作。
S3:在方法结束时,在手势识别器中更新图像并重置导航的左栏按钮项。