我使用苹果文档以编程方式实现组合标签栏和导航,
调用initWithFrame时它不起作用,[黑屏];但如果留下如下代码,它适用于显示主屏幕,没有标签栏,使用标签栏时会黑屏
这里的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( NSDictionary *)launchOptions { self.tabBarController = [[[UITabBarController alloc] init] autorelease]; StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo recomendado por apple!!! VideosViewController* VideosViewController_ = [[[VideosViewController alloc] init] autorelease]; PhotosViewController* PhotosViewController_ = [[[PhotosViewController alloc] init] autorelease]; SocialViewController* SocialViewController_ = [[[SocialViewController alloc] init] autorelease]; self.pagesNavigation = [[[UINavigationController alloc] initWithRootViewController:startViewControllerView] autorelease]; self.pagesNavigation.navigationBarHidden = NO; NSArray* controllers = [NSArray arrayWithObjects:VideosViewController_, PhotosViewController_, SocialViewController_, startViewControllerView, nil]; self.tabBarController.viewControllers = controllers;
[self.window addSubview:startViewControllerView.view];
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
return YES;
}
因此,如果如上所示,它可以工作,但是如果我评论 addSubview 并取消注释 initWithFrame,它就不起作用,,
//[self.window addSubview:startViewControllerView.view];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
那么,我错过了什么?,调用 initWithFrame 的正确方法是什么?
多谢!