iphone组合标签栏和navigationController

发布于 2024-11-30 19:09:07 字数 1839 浏览 4 评论 0原文

我使用 apple 文档以编程方式实现组合标签栏和导航

调用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-12-07 19:09:07

为什么你所有的视图控制器都会自动释放?您可能应该保留它们并仅在使用完它们后才释放它们。

至于您的结构,我发现为 tabbarcontroller 中的每个选项卡构建单个导航控制器,将它们添加到控制器,然后将 tabbarcontroller 添加到窗口,就像这样......

AppDelegate.h

property (nonatomic, retain) UITabBarController *tabBarController;
property (nonatomic, retain) UINavigationController *firstNavController;
property (nonatomic, retain) UINavigationController *secondNavController;
property (nonatomic, retain) FirstViewController *firstViewController;
property (nonatomic, retain) SecondViewController *secondViewController;

AppDelegate.m

firstViewController = [[FirstViewController alloc] someInitMethod:someArg];
firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

secondViewController = [[SecondViewController alloc] someInitMethod:someArg];
secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 

tabBarController = [[UITabbarController alloc] init];

NSArray *tabs = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];

[tabBarController setViewControllers:tabs animated:NO];

self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];

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

property (nonatomic, retain) UITabBarController *tabBarController;
property (nonatomic, retain) UINavigationController *firstNavController;
property (nonatomic, retain) UINavigationController *secondNavController;
property (nonatomic, retain) FirstViewController *firstViewController;
property (nonatomic, retain) SecondViewController *secondViewController;

AppDelegate.m

firstViewController = [[FirstViewController alloc] someInitMethod:someArg];
firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

secondViewController = [[SecondViewController alloc] someInitMethod:someArg];
secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 

tabBarController = [[UITabbarController alloc] init];

NSArray *tabs = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];

[tabBarController setViewControllers:tabs animated:NO];

self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文