【问题标题】:Tab bar application problem标签栏应用问题
【发布时间】:2011-03-20 21:22:31
【问题描述】:

我有基于窗口的应用程序,我添加了 MainMenuViewController .h 和 .m,并在 AppDelegate.m 中创建了 tabBarController

MainMenuViewController *mmvc = [[MainMenuViewController alloc] init]; FavesViewController *fvc = [[FavesViewController alloc] init]; UITabBarController *tbc = [[UITabBarController alloc] init]; tbc.viewControllers = [NSArray arrayWithObjects:mmvc, fvc, nil]; [self.window addSubview:tbc.view];

在 MainMenuViewController 中,我有按钮 - 转到其他视图

-(IBAction)goToTableView { MyViewController *mtvc = [[MyViewController alloc] init]; [self.view addSubview:mvc.view]; }

但是当我按下主菜单 tabBar 项目时,它会加载 MyTableView,而不是 MainMenuViewController。我希望当我按下 tabBar 项 MainMenu 时,它将加载 MainMenuViewController,而不是从 MainMenuViewController 加载的 ViewController。怎么做?谢谢。

【问题讨论】:

    标签: objective-c ios uitabbarcontroller


    【解决方案1】:

    有点难以理解您对代码的意图是什么......您似乎尝试执行以下操作:

    1. 通过标签栏访问的视图控制器之一是显示某种菜单项的表格视图。
    2. 点击菜单中的某个项目应导航到另一个视图控制器。

    如果以上正确,那么您的解决方案是设置标签栏项以显示 UINavigationController 的实例,其中 rootViewController 属性指向 MainMenuViewController 类的实例。

    然后在菜单视图控制器的操作处理程序中,您将执行以下操作:

    MyViewController *mtvc = [[MyViewController alloc] init];
    [self.navigationController pushViewController:mtvc animated:YES];
    [mtvc release], mtvc = nil;
    

    当您想要遍历某种菜单详细信息层次结构时,经验法则是使用导航控制器。

    【讨论】:

    • 不要让 MainMenuViewController 成为 UINavigationController 的子类。相反,使用 MainMenuViewController 的实例创建一个 UINavigationController 作为其根视图控制器,并将其添加到选项卡栏控制器。
    • 是的,你是对的。那里的子类化是错误的。一个普通的 UINavigationController 就可以了。
    • 修复了答案:不再有奇怪的子类化建议 :)
    【解决方案2】:

    你做错了。您应该将 MainMenuViewController 放在 UINavigationController 中,然后使用[self.navigationController pushViewController:mtvc animated:YES] 添加它(如果您需要以编程方式删除它,则使用[self.navigationController popViewControllerAnimated:YES]),或者您应该使用[self presentModalViewController:mtvc animated:YES] 添加它并使用[self dismissModalViewControllerAnimated:YES] 删除它。

    【讨论】:

      【解决方案3】:

      为此添加 navigationController 然后编写

      [self.navigationContrller pushViewController:yourClassName Animation:YES];

      【讨论】:

        猜你喜欢
        • 2013-05-09
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-02
        相关资源
        最近更新 更多