3

I set up my app using a storyboard and have my main view controller embedded in a UINavigationControler. To change the title that appears in the navigation bar, in the viewDidLoad method of my main view controller, I have self.navigationItem.title = @"My Title"; But the title never gets set.

My guess is that I need to set up a Reference Outlet in my storyboard, but I'm not sure what needs to be connected to what. Any ideas?

3 Answers 3

7

in story board, it doesn't get automatically connected , make a UINavigationItem using the following code in ur .h file

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

in .m file synthesize the property and set the title like this

@synthesize navBar;
-(void)viewWillAppear:(BOOL)animated {
[self.navBar setTitle:@"Sign In"];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}

Also, don't forget to connect the UINavigationItem "navBar" in the storyBoard with ur class so that storyboard knows whose title to change. In case u don't have a UINavigationItem in ur storyboard,add it outside the UIView and then connect it properly

3

Just setting the title property of the view controller you are in should do the trick.

[self setTitle:@"Best Page Ever"];
1
  • Hmm, have you tried setting the title before pushing the controller?
    – diatrevolo
    May 30, 2012 at 18:29
0

After you have allocated your rootview..use:-

YourRootView *rootView=[YourRootView alloc]init];
rootView.title=@"yourTitle";

and then initialize it in uinavigationcontroller.(I don't have idea if you have your view on storyboard , then set its title just after allocating and then pass it as parameter to navigationcontroller).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.