0

Right now I've this done programmatically. First I'm creating a button in my UITableViewController subclass.

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.add, target: self, action: Selector(("onNew")))
}

Then

func onNew() {
    self.pushViewController(userForm, animated: true)
}

Question/Problem: I want to change this implementation and no long want to use code but instead options from XCode Design Interface. But I'm not finding any option in my Navigation Controller Attribute window to add a button using design interface. (screenshot 1 & 2)

Attempt I tried to drag and drop a Bar Button Item from objects to Navigation Controller but it always sit next to First Responder or exit. (screenshot 3)

P.S.: To pass data I through segues I've the solution from this answer.

enter image description here

enter image description here

enter image description here

Edit Screenshot 4: to Describe that I'm embedding a UITableViewController within UINavigationController. Any workaround to this exception.

enter image description here

Developer
  • 924
  • 3
  • 14
  • 30

2 Answers2

1
  1. Add a UINavigationItem to the UITableViewController
  2. Add the UIBarButtonItem to the UINavigationItem

I just added a UITableViewController to my storyboard and followed these steps and it worked.

enter image description here

Matias Jurfest
  • 1,378
  • 16
  • 25
0

Add Bar Button Item to View Controller not on the navigation controller.

Here screen shot attached for your reference.

I hope this will help you.

enter image description here

  • I'm using `UITableViewController`, any workaround to this, added a screenshot 4 in my question edit. I'm not using `UIViewController` – Developer Apr 03 '19 at 11:30
  • 1
    I have tried with UITableViewController instead of UIViewController and it worked with same process. – Mohit Gorakhiya Apr 03 '19 at 12:10