iPhone将视图控制器推入导航栏内的标签栏内
我有一个应用程序,它有一个带导航栏的选项卡栏,
选项卡栏正在显示, 并工作,但是当我想转到其中一个选项卡内的另一个页面时,它不会加载新页面,
这里我的应用程序委托
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo recomendado por apple!!!
PhotosViewController* PhotosViewController_ = [[[PhotosViewController alloc] init] autorelease];
VideosViewController* VideosViewController_ = [[[VideosViewController alloc] init] autorelease];
SocialViewController* SocialViewController_ = [[[SocialViewController alloc] init] autorelease];
NSArray* controllers = [NSArray arrayWithObjects: startViewControllerView, VideosViewController_, PhotosViewController_, SocialViewController_, nil];
self.tabBarController.viewControllers = controllers;
self.pagesNavigation = [[[UINavigationController alloc] initWithRootViewController:startViewControllerView] autorelease];
self.pagesNavigation.navigationBarHidden = NO;
[self tabBarConfig];
[self.tabBarController setViewControllers:controllers animated:YES];
[self.window addSubview:self.pagesNavigation.view];
self.window.rootViewController = self.tabBarController;
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
return YES;
}
它显示选项卡正常,
但在其中一个页面中我推送了新视图,
[self.navigationController pushViewController:bigPhotoView animated:YES];
但它没有加载不工作。
那么如何从我的选项卡加载新视图呢?
I have an app that has a tabBar with a navbar,
The tabBar is showing,
and working, but when I want to go to another page inside one of the tabs, it doesnt load the new page,
here my app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo recomendado por apple!!!
PhotosViewController* PhotosViewController_ = [[[PhotosViewController alloc] init] autorelease];
VideosViewController* VideosViewController_ = [[[VideosViewController alloc] init] autorelease];
SocialViewController* SocialViewController_ = [[[SocialViewController alloc] init] autorelease];
NSArray* controllers = [NSArray arrayWithObjects: startViewControllerView, VideosViewController_, PhotosViewController_, SocialViewController_, nil];
self.tabBarController.viewControllers = controllers;
self.pagesNavigation = [[[UINavigationController alloc] initWithRootViewController:startViewControllerView] autorelease];
self.pagesNavigation.navigationBarHidden = NO;
[self tabBarConfig];
[self.tabBarController setViewControllers:controllers animated:YES];
[self.window addSubview:self.pagesNavigation.view];
self.window.rootViewController = self.tabBarController;
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
return YES;
}
it shows tabs ok,
but in one of the pages I push the new view with
[self.navigationController pushViewController:bigPhotoView animated:YES];
but it doesn't work.
So how to load the new view from my tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UINavigationController
是一堆视图控制器。每个视图控制器都有一个名为navigationController
的属性,它代表它所属的UINavigationController
。因此,如果视图控制器不属于UINavigationController
(换句话说,如果视图控制器不存在于堆栈中),它的navigationController
属性将为 nil 。如果你想要一个视图控制器,你可以从中推送新的视图控制器和弹出视图控制器,你需要首先创建一个堆栈(UINavigationController),将你的视图控制器推送到这个堆栈中。现在,由于堆栈存在,我们可以继续在该堆栈中推送新的视图控制器。
您的 bigPhotoView 没有被推送,可能是因为当前视图控制器不存在 UINavigationController (您试图从中推送 bigPhotoView)。这可以如下验证:
在上述情况下,您可能不会输入 if 语句。
我简单地准备了你的功能。它看起来像这样。
这里是苹果的官方文档用于 UINavigationController
UINavigationController
is a stack of view controllers. Every view controller has a property called asnavigationController
, which represents theUINavigationController
to which it belongs. Thus, if a view controller doesn't belong to aUINavigationController
(in other words, if a view controller is not present in a stack), it'snavigationController
property would be nil.If you want to have a view controller from which you could push new view controllers and pop view controllers, you need to create a stack (UINavigationController) first, push your view controller in this stack. Now since stack exists, we can keep pushing new view controllers in this stack.
Your bigPhotoView is not getting pushed probably because there is no UINavigationController existing for the current view controller (from which you are trying to push bigPhotoView). This could be verified as follows:
In the above case, you might not enter the if statement.
I prepared your function briefly. It looks something like this.
Here is the official apple's documentation for UINavigationController