【问题标题】:How to add uitabbarcontroller as a subview in UIViewController如何在 UIViewController 中将 uitabbarcontroller 添加为子视图
【发布时间】:2011-10-02 13:41:34
【问题描述】:

我是 iPhone 开发的新手... 现在我正在尝试构建一个应用程序,其中首先向用户显示登录屏幕。在此视图中没有导航控件。

用户登录后,我想显示一个新视图,该视图具有标签栏控件。根据在选项卡栏中选择的选项卡项目...正在显示的视图可能只有一个表格视图或表格视图 + 导航栏控件。

对此有什么帮助吗?

我能够构建一个小型应用程序来登录屏幕并验证用户凭据.. 还有一个不同的应用程序,我在其中构建了一个 tabbarviewcontroller 并显示将各种视图关联到每个 tabbar 项。

但不确定将两者结合起来。所以问题是我不知道如何将 UITabbarController 添加为第二个视图

请帮帮我。

【问题讨论】:

    标签: iphone cocoa-touch uiviewcontroller uitabbarcontroller


    【解决方案1】:

    你需要做这样的事情。将登录视图从主窗口和 tabbarcontroller 的视图移至主窗口。您只需要在应用程序委托类中实现一些方法即可。

    【讨论】:

    • 对不起,我看不清楚...你能用代码sn-p解释一下吗??
    【解决方案2】:

    将 tabbatcontroller 添加到您的主窗口类。每当您需要在应用程序中使用tabar。只需删除 UINavigationController 并添加 UITabBarController。

    或将 tabbatcontroller 添加到您的主窗口类中,然后从当前视图控制器中显示 tababrcontroller。

    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    delegate.tCtr.selectedIndex = index;
    delegate.tCtr.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:delegate.tCtr animated:YES];
    

    【讨论】:

    • 它在控制台中显示错误。实际上我按照你说的做了,但是在控制台中它显示“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIApplication tabBarController]:发送了无法识别的选择器” ..你有什么主意吗??我的代码是:testTabAppDelegate *del = (testTabAppDelegate *)[UIApplication sharedApplication]; del.tabBarController.selectedIndex = 1; del.tabBarController.modalTransitionStyle = UIModalTransitionStyleFlipHorizo​​ntal; [self presentModalViewController:del.tabBarController Animation:YES];
    • 你给 tababr 的连接 del 了吗?
    • 仍然错误。我做了以下 1. 创建了基于视图的应用程序 2. 在 appDelegate.h 中添加了 UITabbarController 3. 使用 IB 添加了 Tabbarcontroller 到视图控制器 4. 在视图控制器中调用了方法,代码如下:testTabAppDelegate *del = (testTabAppDelegate *)[UIApplication sharedApplication] ; del.tabBarController.selectedIndex = 1; del.tabBarController.modalTransitionStyle = UIModalTransitionStyleFlipHorizo​​ntal; [自我presentModalViewController:del.tabBarController动画:YES];我尽力在 IB 中进行任何连接。这些步骤对吗??我错过了什么或很多东西吗??
    • 在主窗口中添加了 tababrcontroller。并连接到 UITabbarController。
    猜你喜欢
    • 2010-12-01
    • 1970-01-01
    • 2011-09-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    相关资源
    最近更新 更多