Add button to navigationbar programmatically

后端 未结 12 1978
日久生厌
日久生厌 2020-12-04 12:03

Hi I need to set the button on right side, in navigation bar, programatically , so that if I press the button I will perform some actions. I have created the navigation bar

12条回答
  •  离开以前
    2020-12-04 12:20

    Swift version, add this in viewDidLoad:

    var doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: "doneButton:")
    navigationItem.rightBarButtonItem = doneButton
    

    And this in your View Controller class

    func doneButton(sender: UIBarButtonItem) {
        println(111)
    }
    

提交回复
热议问题