Set the title of the navigation bar created in Interface Builder

I have a modal view controller whose view comes from XIB. I want it to look the same as the rest of my navigation-based application, but this is not a view that was ported to the navigation system stack, it was presented modally. I dragged the UINavigationBar and made it exit, but it does not have a title property to set. I have two fields that can display this modal view, and I want the title to be set differently depending on which one creates the modal view.

+51
ios uinavigationbar
Jan 12 '11 at 16:01
source share
8 answers

UINavigationBar manages the UINavigationItem stack, as the UINavigationController manager, the UIViewController s stack. To set what is visible directly, you must use either pushNavigationItem:animated: or setItems:animated: using the navigationItem of the view controller on which you want to display the panel.

eg:

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

The above code in which you have a navigationBar property that refers to a standalone navigation bar.

If you do not want to manage it yourself, you can do as mplappert suggested and insert a view controller (without a standalone UINavigationBar ) into the UINavigationController and present a navigation controller instead of your view controller.

+90
Jan 12 '11 at 16:22
source share

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

 self.navigationBar.topItem.title = title; 
+63
Sep 19 '11 at 23:30
source share

(using XCode 4.5.2) A method was found that works directly in Interface Builder - without any configuration in the code.

In the ViewController object selected in (IB), under the Identity Inspector, there is a section labeled “ Custom Runtime Attributes ”. I added a keypath "title" of type String and set it to the value I wanted.

Tested, and it works when you push the Nav Controller onto the stack and when it opens by default (using the Modal Nav Controller, of course).

+8
Nov 30 '12 at 1:09
source share

viewcontroller.h file in creating iboutlet navigation item

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

- called it "navigationBarTitle"

in viewcontroller.m file add code to super viewDidLoad

  self.navigationBarTitle.title = @"Favorites"; 

connect the narrator in the navigation bar item to the navigationBarTitle.

+4
May 19 '14 at 6:29
source share

in my .h file

  • Drag the child from the navigation item from the storyboard to the .h file

  • Named it "navigationBarTitle"

in my .m file

  • Added self.navigationBarTitle.title = @ "Some name";
0
Jun 28 '13 at 2:18
source share

Here is the easiest way:

 [[[self.navigationController navigationBar] topItem] setTitle:@"The Title"]; 
0
Apr 15 '16 at 8:21
source share

you can use the existing navigation bar with the following code

 self.navigationController?.navigationBar.topItem?.title = "Calender" 
0
Dec 31 '16 at 17:22
source share

Just place the UIViewController in the new stack of the UINavigationController view manager and present the navigation controller in different ways.

-one
Jan 12 2018-11-12T00:
source share



All Articles