0

在基于选项卡的应用程序委托中,我添加了导航控制器,如下所示,

 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;

我将无法在每个视图中添加标题。添加时不显示标题?请帮我解决这个问题

4

5 回答 5

1

使用下面的代码...

在这里,我添加UINavigationController到每个选项卡,并为选项卡分配标题,也为UINavigationBar如下所示...

- (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)或

您也可以简单地在您的特定班级中分配标题,如下所示......

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

我希望这对你有帮助......

于 2013-02-06T06:21:29.213 回答
0

在每个标签栏控制器和使用行中转到 viewdidload 方法:

navigationController.title=@"hello";
于 2013-02-06T06:21:02.667 回答
0

在每个视图控制器 viewdidload self.navigationcontroler.title=@"firstVC";

于 2013-02-06T06:22:49.540 回答
0

“title” 是 的属性,UIViewController并且UINavigationController是您的子类,UIViewController您也可以访问它的对象UINavigationController,就像navviewController.title = @"myTitle";查看Apple Docs一样了解更多详细信息。希望它会有所帮助。干杯

于 2013-02-06T06:26:58.507 回答
0

您已在导航控制器中添加了 TabBar 控制器,因此您无法添加标题并出现此问题。

尝试在 tabbar 控制器中添加带有 View 控制器的每个导航控制器。我的意思是将您的 ViewController 添加为导航控制器的根视图控制器,然后添加到选项卡栏控制器。

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

现在然后将这个导航控制器添加到标签栏控制器中。对所有其他视图控制器执行此操作

于 2013-02-06T06:47:45.457 回答