Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

UberMonjie

macrumors newbie
Original poster
Feb 11, 2009
18
0
I am having trouble setting a title for my navbar.

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {

	UITabBarController *tabBarController = [[UITabBarController alloc] init];
	
	// Init view controllers
	GabViewController *gvc = [[GabViewController alloc] init];
	VoteViewController *vvc = [[VoteViewController alloc] init];

	// Navbar controller, init with root view from Gab View
	UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gvc];
	nav.navigationBar.barStyle = UIBarStyleBlackOpaque;
	nav.navigationItem.title = @"Sayonara Chat";
	nav.title = @"Sayonara Chat";

	
	// Tab bar titles and icons
	nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Gab" image:[UIImage imageNamed:@"icon_root.png"] tag:0];
	vvc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Vote" image:[UIImage imageNamed:@"icon_another.png"] tag:1];
	
	// Add to the tab bar, animated
	[tabBarController setViewControllers:[NSArray arrayWithObjects:nav,vvc, nil] animated:YES];
	
	[window addSubview:tabBarController.view];
	[window makeKeyAndVisible];
}

You can see I am trying two different ways to set the title, neither works?! Also, I can't add buttons to the navbar? I CAN set the barStyle just fine! What gives?

Any thoughts are much appreciated!
 

mars.tsang

macrumors newbie
Nov 25, 2008
12
0
I think you should set the nav's title in its root viewcontroller . the code is like :
self.navigationItem.title = @"Some text ";
 

UberMonjie

macrumors newbie
Original poster
Feb 11, 2009
18
0
Hmmm...

Thanks, although I am little confused, in this case:

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gvc];

do I need to add a "RootViewController"? or is gvc my rootview controller in this case? I can't seem to add a title to this thing either way?!

Thanks for trying to help!
 

mars.tsang

macrumors newbie
Nov 25, 2008
12
0
Thanks, although I am little confused, in this case:

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gvc];

do I need to add a "RootViewController"? or is gvc my rootview controller in this case? I can't seem to add a title to this thing either way?!

Thanks for trying to help!

so gvc is the first viewcontroller of your navigationcontoller ,which mean gvc is the first one in the nav's view controller's stack .
So somewhere in your gvc's source code ,you apply the code:
self.navgationItem.title = @"something ";
 

mars.tsang

macrumors newbie
Nov 25, 2008
12
0
there's also another way to set the nav's title too.
if you set the title property for your gvc ,like self.title = @"some title" and when you set the gvc to be the nav's root view controller or push it into the nav , then the nav's title will be the same as the gvc's .
 

UberMonjie

macrumors newbie
Original poster
Feb 11, 2009
18
0
Ahhh...

Oh, I get it now... Thanks!

I was trying to set the title of the navbar controller FROM the gvc code. I didn't understand the title belongs to the controller that is pushed on to the nav at the time...

Many thanks friend!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.