如何添加2 ViewControllers到同一个窗口 [英] How to add 2 ViewControllers to the same window
问题描述
我在iTunes U中跟随斯坦福的iPhone开发课程,并且我的任务之一有问题(Paparazzi,如果有人熟悉)。
I am following Stanford's iPhone Development course in iTunes U and I'm having problem with one of their assignments (Paparazzi, if anyone is familiar).
'm尝试做是基本上创建这个视图作为应用程序启动时的第一个屏幕:
What I'm trying to do is basically to create this view as the first 'screen' upon application launch:
这是我在应用程序委托中的代码:
And this is the code that I have in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// PersonListViewController is the 'content' of the screen (image, name, and button)
PersonListViewController* personList = [[PersonListViewController alloc] initWithNibName:@"PersonListViewController" bundle:[NSBundle mainBundle]];
navController = [[UINavigationController alloc] initWithRootViewController:personList];
[personList release];
UITabBarController* tabBarController = [[UITabBarController alloc] init];
[window addSubview:[tabBarController view]];
[window addSubview:[navController view]];
[window makeKeyAndVisible];
return YES;
}
但是这个代码似乎没有在底部显示tabBar导航栏和中间的视图(图像,名称和按钮)。
But this code doesn't seem to show the tabBar on the bottom, only the navigation bar and the view in the middle (image, name, and the button).
有人可以向我解释我做错了什么,如何解决? / p>
Can someone explain to me what I did wrong and how to fix it?
推荐答案
你通常做的是嵌套你的主要ViewController(在这种情况下, PersonListViewController
)in UINavigationController
(像你做的),但是你设置 tabBarController.viewControllers
属性等于
What you typically do is nest your main ViewController (in this case, PersonListViewController
) inside a UINavigationController
(like you have done), but then you set the tabBarController.viewControllers
property equal to an array of view controllers (one for each tab).
在这种情况下,这将是
tabBarController.viewControllers = [NSArray arrayWithObject:navController];
然后只将tabBarController的视图添加到窗口
Then add only the tabBarController's view to the window
[window addSubview:[tabBarController view];
这将给你的列表,在nav控制器内,tab控制器将只有一个标签,现在)。
This will give you your list, inside a nav controller, inside a tab controller (and the tab controller will only have one tab, for now).
这篇关于如何添加2 ViewControllers到同一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!