How can the action for a custom UIBarButtonItem in Swift be set?
The following code successfully places the button in the navigation bar:
var b = UIB
@objc, see below example!#selector(name).private or public doesn't matter; you can use private.override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let menuButtonImage = UIImage(systemName: "flame")
let menuButton = UIBarButtonItem(image: menuButtonImage, style: .plain, target: self, action: #selector(didTapMenuButton))
navigationItem.rightBarButtonItem = menuButton
}
@objc public func didTapMenuButton() {
print("Hello World")
}