我的应用程序有一个带导航栏的tabBar,
tabBar正在显示, 并且工作,但是当我想转到其中一个标签内的另一个页面时,它不会加载新页面,
这是我的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;
}
它显示标签确定,
但是在其中一个页面中我用
推送新视图[self.navigationController pushViewController:bigPhotoView animated:YES];
但它不起作用。
那么如何从我的标签加载新视图?
答案 0 :(得分:5)
UINavigationController
是一堆视图控制器。每个视图控制器都有一个名为navigationController
的属性,它表示它所属的UINavigationController
。因此,如果视图控制器不属于UINavigationController
(换句话说,如果视图控制器不在堆栈中),那么它的navigationController
属性将为零。
如果你想拥有一个可以推送新视图控制器和弹出视图控制器的视图控制器,你需要首先创建一个堆栈(UINavigationController),在这个堆栈中推送你的视图控制器。现在,由于堆栈存在,我们可以继续在此堆栈中推送新的视图控制器。
你的bigPhotoView可能没有被推动,因为当前的视图控制器(你从中尝试推送bigPhotoView)没有UINavigationController。这可以通过以下方式验证:
if (self.navigationController != nil) {
[self.navigationController pushViewController:bigPhotoView animated:YES];
}
在上述情况下,您可能不会输入if语句。
我简要地准备了你的功能。它看起来像这样。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create Start view controller.
StartViewController *startController = [[StartViewController alloc] init];
UINavigationController *startViewNavigationController = [[UINavigationController alloc] initWithRootViewController:startController];
[startController release];
// Similarly create for photos, videos and social...
// Create an array of view controllers.
NSArray* controllers = [NSArray arrayWithObjects:startViewNavigationController, photosViewNavigationController, videosViewNavigationController, socialViewNavigationController, nil];
// Create our tab bar controller.
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
// Set the view controllers of the tab bar controller.
self.tabBarController.viewControllers = controllers;
// Release the startViewNavigationController, photosViewNavigationController, videosViewNavigationController, socialViewNavigationController...
// I don't know what this does.
[self tabBarConfig];
// Add the tab bar controller to the window.
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
Here是UINavigationController的官方苹果文档