Omar Dadabhoy
Omar Dadabhoy

Reputation: 59

Why does the UIBarButtonItem not show up when I create it with code?

When I create a UIBarButton programatically in the viewDidLoad() method it does not show up when I run the program. I am not sure what is happening. Sorry I am new to xcode and do not understand how everything works.

var menuButton: UIBarButtonItem = UIBarButtonItem()

override func viewDidLoad() {


    super.viewDidLoad()
    // creating the refresh control object
    menuButton = UIBarButtonItem.init(title: "Menu", style: .plain, target: self, action: nil)

}

It should create a UIBarButton in the navigation controller, instead there is nothing there.

Upvotes: 0

Views: 33

Answers (1)

AdamPro13
AdamPro13

Reputation: 7400

You need to set navigationItem.rightBarButtonItem = menuButton

Upvotes: 2

Related Questions