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?
UINavigationControlleris a stack of view controllers. Every view controller has a property called asnavigationController, which represents theUINavigationControllerto 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’snavigationControllerproperty 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