【问题标题】:Combining UINavigationController with UITabBarController将 UINavigationController 与 UITabBarController 结合使用
【发布时间】:2012-11-14 18:55:17
【问题描述】:

我正在开发一个 iOS 应用程序,它要求用户在使用该功能之前登录或注册。流量是; 该应用程序显示一个带有 2 个按钮的屏幕 1) 登录 2) 注册 单击任一按钮后,应用程序使用 UiNavigationController 将用户导航到不同的视图控制器。 成功登录后,用户将被定向到一个主视图控制器,该控制器在视图底部显示一个标签栏,在视图顶部显示一个 UiNavigationController 的顶部栏。

为了实现这一点,我将 UINavigationViewController 设置为 AppDelegate 文件中的根视图控制器。

用户通过身份验证后,我使用以下代码将标签栏控制器推送到 UiNavigationController 上。

    FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    [firstViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"1st" image:[UIImage imageNamed:@"1st.png"] tag:101]];

    SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [secondViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"2nd" image:[UIImage imageNamed:@"2nd.png"] tag:102]];

    ThirdViewController *thirdViewController = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
    [thirdViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"3rd" image:[UIImage imageNamed:@"3rd.png"] tag:104]];


    UITabBarController *tabController = [[UITabBarController alloc] init];
    [tabController setViewControllers:[NSArray arrayWithObjects:firstViewController, secondViewController,thirdViewController, nil]];

    [self.navigationController pushViewController:tabController animated:YES];

这是正确的方法吗? 刚才有人说使用标签栏控制器作为根视图控制器将是一个更好的方法。 如何将标签栏控制器设置为根视图控制器,因为我不想在登录/注册屏幕上显示标签栏....

谢谢!

【问题讨论】:

    标签: ios uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    只需创建一个协议,您就可以在您的登录名UIViewController 和您的AppDelegate 之间进行通信。登录完成后,您可以更改rootViewController。您还可以通过执行以下操作来获取对 AppDelegate 的引用:

    MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    

    虽然我更喜欢使用协议在不同对象之间进行通信。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多