iphone组合标签栏和navigationController
调用initWithFrame时不起作用,[黑屏];但如果保留下面的代码,它可以用于显示主屏幕,没有选项卡栏,并且当使用选项卡栏时,
这里的代码
会变成黑屏- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( NSDictionary *)launchOptions { self.tabBarController = [[[UITabBarController alloc] init] autorelease]; StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo 推荐苹果! 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* 控制器 = [NSArray arrayWithObjects:VideosViewController_, PhotosViewController_, SocialViewController_, startViewControllerView, nil]; self.tabBarController.viewControllers = 控制器;
[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 的正确方法是什么?
多谢!
Im implementing a combined tab bar and navigation programatically, using the apple documentation,
it is not working when calling the initWithFrame,[goes black screen]; but if left as below code it works for showing main screen, with out the tab bar, and when using the tab bar goes black screen
here the code
- (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;
}
so if left as shown above, it works but if I comment the addSubview and uncomment the initWithFrame, it doesnt work,,
//[self.window addSubview:startViewControllerView.view];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
So, what Im i missing?,
what would be the right way to call the initWithFrame?
thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你所有的视图控制器都会自动释放?您可能应该保留它们并仅在使用完它们后才释放它们。
至于您的结构,我发现为 tabbarcontroller 中的每个选项卡构建单个导航控制器,将它们添加到控制器,然后将 tabbarcontroller 添加到窗口,就像这样......
AppDelegate.h
AppDelegate.m
Why are all your viewcontrollers auto released? You should probably be retaining them and releasing them only when you're done with them.
As for your structure, I've found that building a single navigation controller for each tab in the tabbarcontroller, adding those to the controller, then adding the tabbarcontroller to the window works like this...
AppDelegate.h
AppDelegate.m