【问题标题】:Can I change the first screen of tab item programatically?我可以以编程方式更改选项卡项的第一个屏幕吗?
【发布时间】:2012-11-16 03:16:36
【问题描述】:

我能否以编程方式更改选项卡项的第一个屏幕?

例如,

当用户在选项卡 A 中时,点击那里的按钮,用户将 使用屏幕 1 导航到选项卡 C 但是,当用户在选项卡 C 中时, 点击此处的按钮,用户将被导航到具有屏幕 2 的选项卡 C。 因此,屏幕 1 和 2 都将是 Tab C 的第一个屏幕 取决于用户来自哪里。

我能实现这样的目标吗? 谢谢!

【问题讨论】:

    标签: ios uitabbarcontroller uitabbar


    【解决方案1】:

    根据How to replace a navigation root controller by tab bar controller in existing iphone app这个帖子,可以通过以下代码更改视图控制器:

    NSMutableArray * viewControllers = [[NSMutableArray alloc]init];
    
    
    FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
    UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
    [firstViewController release];
    [viewControllers addObject:nvc];
    [nvc release];
    
    SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
     nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
    [secondViewController release];
    [viewControllers addObject:nvc];
    [nvc release];
    
    UITabBarController * tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = viewControllers;
    [window addSubview:tabBarController.view];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      相关资源
      最近更新 更多