Set the title of Navigation Bar created in Interface Builder

前端 未结 8 1741
挽巷
挽巷 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:27

    (Using XCode 4.5.2) Found a method that works directly in Interface Builder - without setting in code.

    With the ViewController object selected in (IB), under the Identity Inspector there is a section labeled "User Defined Runtime Attributes". I added the keyPath "title" of type String and set it to the value I wanted.

    Tested and this works when pushed onto a Nav Controller stack and when opened modally (with a Modal Nav Controller of course).

    0 讨论(0)
  • 2020-12-24 05:28

    you can use existing navigation bar with following code

    self.navigationController?.navigationBar.topItem?.title = "Calender"
    
    0 讨论(0)
  • 2020-12-24 05:29

    Simply put your UIViewController into a new UINavigationControllers view controller stack and present that navigation controller modally.

    0 讨论(0)
  • Here is the Simplest way:

    [[[self.navigationController navigationBar] topItem] setTitle:@"The Title"];
    
    0 讨论(0)
  • 2020-12-24 05:35

    in my .h file

    • Dragged the Child of the navigation item from the storyboard into the .h file

    • Named it "navigationBarTitle"

    in my .m file

    • Added self.navigationBarTitle.title = @"Some Title";
    0 讨论(0)
  • 2020-12-24 05:41

    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;
    
    0 讨论(0)
提交回复
热议问题