【问题标题】:navigationcontroller title and button导航控制器标题和按钮
【发布时间】:2013-01-21 06:43:26
【问题描述】:

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

 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;

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

【问题讨论】:

标签: iphone ios6 uinavigationcontroller


【解决方案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";
}

希望对你有帮助...

【讨论】:

    【解决方案2】:

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

    navigationController.title=@"hello";
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

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

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

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

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-12-01
            • 2011-11-30
            • 2012-04-30
            • 2012-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多