UINavigationController 推 UITabBarController 只显示一个选项卡
我有一个应用程序,它在 IB 中创建了一个 UITabBarController
。该 tbc 加载了 3 个视图,到目前为止工作正常。
我决定插入 UINavController
作为起始 VC,并让 UITableViewController
在单元格中显示 4 个菜单项。这 4 个项目中的每一个本质上都会加载 UITabBarController
将传递放入不同的 xml 文件中进行处理,以便在这 3 个选项卡中显示数据。
我基本上是在 applicationDidFinishLoading
结束时执行此操作:
MainMenu *rootViewController = [[MainMenu alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = navController;
[window makeKeyAndVisible];
return YES;
然后我创建了 MainMenu 作为 rootViewController
子类 UITableViewController
并添加了一个硬编码数组,其中显示我想要的 4 件商品。我让 didSelectRowAtIndexPath
运行此代码:
tabBarController = [[UITabBarController alloc] init];
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];
事实证明,当我运行它时,导航控制器会推送选项卡控制器,但只显示第一个选项卡。这是一张照片。
I have an application that has a UITabBarController
created in IB. That tbc loads 3 views which work fine up to now.
I decided to INSERT a UINavController
as the starting VC and have a UITableViewController
display 4 menu items in cells. Each of the 4 items will in essence load the UITabBarController
put pass in a different xml file to process in order to display data in those 3 tabs.
I essentially did this at the end of the applicationDidFinishLoading
:
MainMenu *rootViewController = [[MainMenu alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = navController;
[window makeKeyAndVisible];
return YES;
I then created the MainMenu as the rootViewController
subclassing UITableViewController
and added a hardcoded array for now which displays the 4 items I want. I had the didSelectRowAtIndexPath
run this code:
tabBarController = [[UITabBarController alloc] init];
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];
It turns out that when I run it, the navcontroller pushes the tab controller but only the first tab shows up. Here is a pic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您永远不应该从
UINavigationController
推送UITabBarController
。苹果明确表示:使用标签栏控制器的应用程序也可以在一个或多个标签中使用导航控制器。当在同一个用户界面中组合这两种类型的视图控制器时,标签栏控制器始终充当导航控制器的包装器。`
这本质上意味着标签栏应该是所有其他被调用的视图控制器。反之则不然。您可能应该改变展示应用程序的方式。
更多信息请参见此处。
You should never push a
UITabBarController
from aUINavigationController
. Apple clearly says this:An app that uses a tab bar controller can also use navigation controllers in one or more tabs. When combining these two types of view controller in the same user interface, the tab bar controller always acts as the wrapper for the navigation controllers.`
That essentially means tab bar should be the parent of all other view controllers that get called. Not the other way round. You should probably change the way you present your app.
More information here.