MohanRaj S
MohanRaj S

Reputation: 2008

navigationcontroller title and button

In my tab based application delegate i added the navigation controller as like the following,

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
 UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

 UIViewController *viewController3 = [[view1 alloc] initWithNibName:@"view1" bundle:nil];
 UIViewController *viewController4 = [[view2 alloc] initWithNibName:@"view2" bundle:nil];
 UIViewController *viewController5 = [[view3 alloc] initWithNibName:@"view3" bundle:nil];
 self.tabBarController = [[UITabBarController alloc] init];
 self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3,viewController4,viewController5];
 navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
 [self.window addSubview:[navigationController view]];
self.window.rootViewController = self.navigationController;

i would not be able to added the title in each view. While adding it doesn showing the title?Pls help me to resolve this issue

Upvotes: 0

Views: 118

Answers (5)

Satish Azad
Satish Azad

Reputation: 2312

You have added TabBar Controller inside a Navigation Controller so you cannot add title and arises this issue.

Try to add each navigation controller with View controller inside tabbar controller. I mean add ur ViewController as a root View controller of navigation controller then add to tab Bar controller.

viewController1 = [[[YourViewController1 alloc] initWithNibName:@"YourViewController1" bundle:nil] autorelease];
        navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];

Now then ad this navigation controller inside to tabbar controller. Do this for all other viewcontrollers

Upvotes: 0

Paras Joshi
Paras Joshi

Reputation: 20541

use bellow code...

Here i add UINavigationController to every tab and also assign title for tab and also for UINavigationBar like bellow...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5;
    UINavigationController *navviewController1 , *navviewController2, *navviewController3, *navviewController4, *navviewController5;
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController1 = [[[YourViewController1 alloc] initWithNibName:@"YourViewController1" bundle:nil] autorelease];
        navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
        navviewController1.title = @"Home";
        //        navviewController1.navigationBarHidden=YES;

        viewController2 = [[[YourViewController2 alloc] initWithNibName:@"YourViewController2" bundle:nil] autorelease];
        navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
        //        navviewController2.navigationBarHidden=YES;
        navviewController2.title = @"HowItsWork";

        viewController3 = [[[YourViewController3 alloc] initWithNibName:@"YourViewController3" bundle:nil] autorelease];
        navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
        //        navviewController3.navigationBarHidden=YES;
        navviewController3.title = @"Join Us";


        viewController4 = [[[YourViewController4 alloc] initWithNibName:@"YourViewController4" bundle:nil] autorelease];
        navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
        //        navviewController4.navigationBarHidden=YES;    
        navviewController4.title = @"Become";  

        viewController5 = [[[YourViewController5 alloc] initWithNibName:@"YourViewController5" bundle:nil] autorelease];
        navviewController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
        //        navviewController4.navigationBarHidden=YES;    
        navviewController5.title = @"Contact Us"; 
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2,navviewController3,navviewController4,navviewController5, nil];
        self.window.rootViewController = self.tabBarController;
    }

    [self.window makeKeyAndVisible];
}

2)OR

Also you can simple assign title in your particular class like bellow...

-(void)viewWillAppear:(BOOL)animated{
    self.title = @"yourTitle";
}

i hope this helpful to you...

Upvotes: 1

josh
josh

Reputation: 1689

"title" is the property of UIViewController and UINavigationController is the subclass of UIViewController you can also access it object of UINavigationController, just like navviewController.title = @"myTitle"; and for more detail check Apple Docs. Hope it will help. Cheers

Upvotes: 0

Durgaprasad
Durgaprasad

Reputation: 1951

In every viewcontroller viewdidload self.navigationcontroler.title=@"firstVC";

Upvotes: 0

Vishal
Vishal

Reputation: 8256

Go to viewdidload method in every tabbar controller & use line:

navigationController.title=@"hello";

Upvotes: 0

Related Questions