Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

self.navigationController is nil second time ViewController is loaded

I have a delegate/handler that i have implemented on my UIViewControllers to handle timeouts to the a remote webservice. When a request is made to my webservice, and a timeout http code is returned, the delegate is called and performs the following:

UINavigationController *navController = self.navigationController;

if (navController) {
    [navController popToRootViewControllerAnimated:YES];
} else {
    NSLog(@"navController is null/nil");
}

If I do the following steps, navController is instantiated correctly and the popToRootViewController action occurs.

  1. Authenticate my app with the webservice on a Login ViewController
  2. Auto trigger a segue to a CustomMenuViewController
  3. Wait for the webservice to timeout remotely
  4. Click to trigger a segue to CustomSubMenuViewController

Now, if i do the following steps, the else clause in the above code block is triggered because for some reasons navController isn't being set correctly:

  1. Authenticate my app with the webservice on a CustomLoginViewController
  2. Auto segue to a CustomMenuViewController
  3. Immediately click to trigger a segue to CustomSubMenuViewController
  4. Click back button to trigger a pop
  5. Wait for the webservice to timeout remotely
  6. Click to trigger a segue to the same CustomSubMenuViewController

My question is: why when i load a ViewController for the second time, does self.navigationController return null?

The call stack in the above example should look like this: NavigationController -> CustomLoginViewController -> CustomMenuViewController -> CustomSubMenuViewController

Thanks

UPDATE: Still haven't made any progress on this issue!

like image 201
doug Avatar asked Jul 10 '13 16:07

doug


2 Answers

Hey this might sound really basic but, have you allocated the Navbar object correctly, Maybe you can try setting its property as strong.It maybe so that it is getting deallocated before time.

like image 53
iOsDude Avatar answered Nov 09 '22 23:11

iOsDude


I think you might have already resolved this but i encountered the exact same thing. And I think we might be doing the exact same thing like using facebook for login. Anyway for some one else in the future this might be useful. The issue that i had that i was re allocating the UINavigationController again when coming back from background on a failure condition.

So what you can do is try to put a breakpoint around the place where you initialise your rootViewController for the UiNavigationController.

 [[UINavigationController alloc]
        initWithRootViewController:viewController]; and make sure that you do re-initailise your UINavigationController if you have already done it.
like image 42
adhyeta Avatar answered Nov 09 '22 22:11

adhyeta