不是从 appDelegate 添加 UITabBarController 吗?
是只有我一个人还是我在网上看到的 uitabbarcontroller 的所有示例都需要修改 appDelegate?如果标签栏稍后出现在应用程序中并且之前有一些其他屏幕怎么办?有人可以解释一下这一点或指出应用程序的第一个屏幕不是选项卡栏视图的示例吗?我对此感到抓狂,如果不是来自 AppDelegate,似乎无法让选项卡栏工作。
谢谢!!!
更新:
所以我在我的一个视图控制器中使用一种方法执行此操作,一旦您单击按钮移动到下一个屏幕(即选项卡栏视图),该方法就会触发。它在执行过程中崩溃:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
UIViewController *viewController2 = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; //CRASHES HERE
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
知道为什么吗?谢谢!!
它在这一行崩溃:
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; //CRASHES HERE
Is it just me or literally ALL the examples that I have seen on the web for uitabbarcontroller require modifying the appDelegate? What if the tabbar comes later on in the app and there are some other screens before? Can someone explain this or point to an example where the first screen of the app is NOT a tabbar view? I am getting nuts from this and cant seem to be able to have the tabbar to work if not from the AppDelegate.
Thanks!!!
UPDATE:
So I am doing this in one of my view controllers in a method that triggers once you click on a button to move to the next screen (which is the tab bar view). It crashes during the execution:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
UIViewController *viewController2 = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; //CRASHES HERE
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Any idea why? Thanks!!
It crashes in this line:
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; //CRASHES HERE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将UITabBarController从任何视图控制器推送到导航控制器。这样做可能会折叠导航栏,因为 UITabBarController 中的视图控制器本身可能包含 UINavigationController。
为了解决这个导航栏问题,您需要从推送选项卡栏控制器的视图控制器中隐藏当前导航控制器的导航栏。在当前视图控制器的 viewWillDisappear: 方法中隐藏导航栏。
You can push the UITabBarController to the navigation controller from any view controller. Doing so may collapse the navigation bars as the view controllers in UITabBarController may themselves contain UINavigationController.
In order to overcome this navigation bar issue, you need to hide the navigation bar of the current navigation controller from the view controller where you push the tab bar controller. Hide the navigation bar in viewWillDisappear: method of the current view controller.
好的,我们开始吧。假设mainWindow.xib有1个UINavigationController和1个TabBarController。前几个屏幕是用导航控制器设计的,稍后当您想要 tabBarController 时,您需要做的就是从 mainWindow 中删除 navigationController 的视图并将 tabBarController 的视图添加为窗口的子视图。如果不告诉我,我希望你能理解。
Ok here we go. Suppose mainWindow.xib has one UINavigationController and one TabBarController. First few screens are deisgned with navigation controller later at some point when you want tabBarController what you need to do is just remove the navigationController's view from mainWindow and add tabBarController's view as a subview to window. I hope you understand if not let me know.
http://developer.apple.com/库/ios/#DOCUMENTATION/UIKit/Reference/UITabBarController_Class/Reference/Reference.html
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITabBarController_Class/Reference/Reference.html