Set the title of Navigation Bar created in Interface Builder

前端 未结 8 1742
挽巷
挽巷 2020-12-24 05:18

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 pu

相关标签:
8条回答
  • 2020-12-24 05:50

    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.

    0 讨论(0)
  • UINavigationBar's manage a stack of UINavigationItems much like a UINavigationController manager a stack of UIViewControllers. To set what is visible directly, you should use either pushNavigationItem:animated: or setItems:animated: using the navigationItem of the view controller you want the bar to reflect.

    eg:

    self.navigationItem.title = @"A custom title";
    [self.navigationBar pushNavigationItem:self.navigationItem animated:NO];
    

    The above code where you have a property navigationBar which references the stand-alone navigation bar.

    If you don't want to manage it yourself, you can do as mplappert suggested and nest your view controller (without a stand-alone UINavigationBar) in a UINavigationController and present the navigation controller modally instead of your view controller.

    0 讨论(0)
提交回复
热议问题