Search code examples
iosswiftxcodenavbaruibarbuttonitem

NavBar button will not drag into top right corner of UIViewController


I have 2 UIViewControllers. VC1 i embedded into a Navigation controller. I clicked and dragged a UIBarButtonItem to the top right of this VC. I set this button to segue to VC2. When I try to click and drag a UIBarButton Itemt into VC2 it will not stay in the top right corner. i snaps to the bottom left corner. I know I can do it programatically using self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(handleDone)) ButI want to know why I can't do it in storyboard? as I prefer using it.

enter image description here

enter image description here


Solution

  • It's not a trivial gesture, but you can do it. The problem is that you are dropping the bar button item in the wrong place. Make sure you are hovering the bar button item over the right side of the navigation bar until it "lights up", as shown below:

    enter image description here