1

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];
}
Wali Haider
  • 1,202
  • 1
  • 16
  • 23
  • Can you post some code?? You description seems fine. – Rashad Jan 16 '14 at 06:11
  • @walinaqvi, please do post some code, you explained your problem very well. It's most likely that youre not pushing properly somewhere – Pavan Jan 16 '14 at 06:12
  • Sure, here is my code,in for pushing new viewController i'm using:[self.navigationController pushViewController:MyViewContrller animated:NO]; to pop Viewcontroller i;'m using:[self.navigationController popViewControllerAnimated:NO ]; – Wali Haider Jan 16 '14 at 06:15
  • @walinaqvi ok, ill try explaining what to do and you wont have your problem anymore, i'll let you know when the tutorial is done for you. – Pavan Jan 16 '14 at 06:22
  • @walinaqvi check my code, it works fully and you should implement it exactly as it is by making sure you delete all your current pushing and popping code :) I also suggest maybe creating a new project when you want to follow my tutorial because that will definitely work. And if you receive any errors then you havent deleted your old popping and pushing code properly. Goodluck with my tutorial mate. It took me 25 minutes to write, so follow the code properly ;) lol – Pavan Jan 16 '14 at 06:50
  • 1
    @walinaqvi please ignore everything that Pavan has said in his answer. You should NEVER put anything in the app delegate. It is a VERY bad thing to do. Just please don't do it. – Fogmeister Jan 16 '14 at 09:12
  • 1
    @walinaqvi agree with fogmeister. Also, I see that you've actually found the cause of the problem - you can answer your own question and accept that as well. – jrturton Jan 16 '14 at 09:50
  • ok,i'll do that @jrtuton – Wali Haider Jan 16 '14 at 11:24

1 Answers1

1

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.

Wali Haider
  • 1,202
  • 1
  • 16
  • 23