ios - How to add a NavigationItem to a programmatically created UINavigationController -


i using code programmatically add uinavigationcontroller existing uiviewcontroller:

    self.window = uiwindow(frame: uiscreen.mainscreen().bounds)     let nav1 = uinavigationcontroller()     let mainview = remindercontroller(nibname: nil, bundle: nil)     nav1.viewcontrollers = [mainview]     self.window!.rootviewcontroller = nav1     self.window?.makekeyandvisible() 

now want add title navigationbar managed uinavigationcontroller error:

cannot call pushnavigationitem:animated: directly on uinavigationbar managed controller

the code used:

let item = uinavigationitem(title: "reminder") nav1.navigationbar.pushnavigationitem(item, animated: false) 

any other method tried gave me same error. how add title navcontroller?

the navbar looks right now:

enter image description here

your navigationbar managed navigationcontroller, can't push item directly it. instead should set navigationitem on mainview , navigationcontroller take care of pushing bar

also, check out documentation uinavigationcontroller, think can give better understanding of how navigationcontroller works.

this it:

a navigation controller builds contents of navigation bar dynamically using navigation item objects (instances of uinavigationitem class) associated view controllers on navigation stack.


Comments