Reputation: 1272
I know this question have asked by many users but I did not find the appropriate solution for my issue.
I'm using splitViewController
,I have hidden my rootViewController
and in detailViewController
I'm pushing and popping the different ViewControllers
.
When I'm navigating from ViewController-1
to ViewController-2
its going fine, when I'm returning back to ViewController-1
from viewController-2
using [self.navigationController popViewControllerAnimated:NO ];
again its working fine.
Now when I navigate from ViewController-2
to ViewController-3
and returning back to ViewController-2
its working fine.
But now when I'm returning back from ViewController-2
to ViewController-1
its being crash with following error.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist
I have enabled zombie object. image
code for my app is given below: 1.AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.splitViewController =[[UISplitViewController alloc]init];
// create master and detailViewController for splitView
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil] ;
//create navigation controller for root and detailViewController
self.rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
self.detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
//make hide navigation bar
self.rootNav.navigationBarHidden = YES;
self.detailNav.navigationBarHidden = YES;
//set splitViewController with root and detail viewController
self.splitViewController.viewControllers=[NSArray arrayWithObjects:self.rootNav,self.detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Now Add the split view controller's view to the window and display.
[self.window addSubview:self.splitViewController.view];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
2.push and pop ViewControllers
push()
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
MyViewController *Vc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[appDelegate.detailNav pushViewController:Vc animated:NO];
}
pop()
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.detailNav popViewControllerAnimated:NO];
}
Upvotes: 1
Views: 5484
Reputation: 1272
finally i found the solution, it was very silly mistake,my ViewController-3 was the delegate of UINavigationController.
when i was trying to pop viewController-2 to viewController-1 my UINavigationController was looking for its delegate method - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
in viewController-3 which was already poped.
i made the rootViewController to the delegate of UINavigationController,now its working fine.
Upvotes: 1