I am attempting so as to add the identical button to the navigation bar of every of my screens. I created the next class:
import UIKit
class UIHelper {
static func addEnvelopeIcon(to viewController: UIViewController) {
let envelopeImage = UIImage(named: "feedback")
let envelopeButton = UIBarButtonItem(picture: envelopeImage, fashion: .plain, goal: viewController, motion: #selector(viewController.envelopeButtonTapped))
viewController.navigationItem.rightBarButtonItem = envelopeButton
}
static func showCommentPopup(from viewController: UIViewController, sourceViewControllerName: String) {
let alert = UIAlertController(title: "Go away a Remark", message: "From: (sourceViewControllerName)", preferredStyle: .alert)
alert.addTextField { textField in
textField.placeholder = "Enter your remark right here..."
}
let submitAction = UIAlertAction(title: "Submit", fashion: .default) { _ in
let remark = alert.textFields?.first?.textual content ?? ""
print("Remark from (sourceViewControllerName): (remark)")
}
alert.addAction(submitAction)
alert.addAction(UIAlertAction(title: "Cancel", fashion: .cancel, handler: nil))
viewController.current(alert, animated: true, completion: nil)
}
}
I name it like this:
override func viewDidLoad() {
tremendous.viewDidLoad()
UIHelper.addEnvelopeIcon(to: self)
}
The button does not seem. No errors are thrown and I’ve verified that the feedback.png picture is in Property.