如何在使用选项卡视图控制器的页面中为第一个导航控制器设置标题。

时间:2013-02-22 07:29:03

标签: ios objective-c uinavigationcontroller

我们在app delegate中使用了以下代码。但我们在导航控制器的setTitle函数中遇到错误。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    UIViewController* viewController3=[[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3, nil];
    NavigationViewController* navigationViewController=[[NavigationViewController alloc]initWithRootViewController:self.tabBarController];
  self.navigationItem.title=@"news";
    self.window.rootViewController = navigationViewController;
    [self.window makeKeyAndVisible];

    return YES;
}

2 个答案:

答案 0 :(得分:1)

self.navigationItem.title=@"your navigation title";

使用此视图控制器来显示标题

答案 1 :(得分:0)

[viewController1 setTitle:@"Title1"];
[viewController2 setTitle:@"Title2"];
[viewController3 setTitle:@"Title3"];

导航控制器和标签栏控制器都没有标题。