3

I've noticed that if I have a UIViewController in a UINavigationController, something like:

let vc = UIViewController()
let nav = UINavigationController()
nav.viewControllers = [vc]
self.presentViewController(nav, animated: true, completion: nil)

Adding a button the navigation bar is as easy as: vc.navigationItem.leftBarButtonItem = ...

If however, the view controller is of type ABPersonViewController, like this:

let person = ABPersonViewController()
person.personViewDelegate = self
person.displayedPerson = info
let nav = UINavigationController()
nav.viewControllers = [person]
self.presentViewController(nav, animated: true, completion: nil)

I can't add a button the navigation bar in the same way; person.navigationItem.leftBarButtonItem = ..., as seems to be done here, does nothing.

Is there, then, a way to add a button to the navigation bar of an ABPersonViewController?

Community
  • 1
  • 1
Randoms
  • 2,110
  • 2
  • 20
  • 31

2 Answers2

0

You cannot add a button on ABPersonViewController. Even if you are able to add, it will be rejected by apple. What you can do is make a custom view like ABPersonViewController and change whatever you want in it. (My personal opinion is that ABPersonViewController is fine and you should not have a problem living with it).

Fawad Masud
  • 12,219
  • 3
  • 25
  • 34
  • I'm hesitant to make a custom view, seeing as since `ABPersonViewController` can't be subclassed, I would have to write it in its entirety—I'd rather find a workaround. – Randoms Aug 20 '15 at 16:33
0

Your best bet is to just create a View Controller file for your ABPersonViewController and set the button normally in viewDidLoad.

ie:

self.navigationItem.leftBarButtonItem = menuButton

You could add the button to the bar non-programatically by adding a Navigation Item to the view and then adding a bar button item.

Cole
  • 2,641
  • 1
  • 16
  • 34
  • I can't create a file for it because I can't have my VC class inherit from it—I would just have to create an instance of it and present it anyway. – Randoms Aug 20 '15 at 16:46