Set the title of Navigation Bar created in Interfa

2019-01-31 16:21发布

I have a modal view controller whose view comes from a XIB. I want it to have the same look and feel as the rest of my navigation based app, but it's not a view that's pushed to the navigation stack, it's presented modally. I dragged a UINavigationBar in and made it an outlet, but it doesn't have a title property to set. I have two fields that can bring up this modal view, and I want the title set differently depending on which one creates the modal view.

8条回答
Evening l夕情丶
2楼-- · 2019-01-31 17:15

viewcontroller.h file in create iboutlet of the navigation item

     @property (weak, nonatomic) IBOutlet UINavigationItem *navigationBarTitle;

- Named it "navigationBarTitle"

in viewcontroller.m file in add the code in super viewDidLoad

      self.navigationBarTitle.title = @"Favorites";

connect the storybord in navigation bar item to navigationBarTitle.

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-31 17:18

Also found this easier way if you've already defined a UINavigationBar in your IB. Assuming self.navigationBar is your IBOutlet:

self.navigationBar.topItem.title = title;
查看更多
登录 后发表回答