7

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!

bneely
  • 9,083
  • 4
  • 38
  • 46
doug
  • 1,963
  • 2
  • 16
  • 24
  • Have you ruled out any of the causes described at http://stackoverflow.com/a/7767160/1445366 and http://stackoverflow.com/q/1983620/1445366? – Aaron Brager Jul 10 '13 at 16:31
  • Yes - self.navigationController is accessible when the viewController is loaded for the first time, it is only null when you navigate away from it and then try to return to it in succession. – doug Jul 10 '13 at 16:36
  • maake sure that you are not making it null in ViewDidDisappear or ViewdidUnload – Navi Jul 11 '13 at 13:45
  • @Navi thank you for your comment. I am not making it null in either of those methods. – doug Jul 11 '13 at 15:30
  • so u r not using self.navigationcontroller=nil in any where in your code? – Navi Jul 12 '13 at 04:16
  • I have the some problem. I can see the Navigation Bar (which I thought was supposed to be part of the Navigation Controller), but `NavigationController` is null so I can't get `NavigationBar` from it! Is there another way to get to the Navigation Bar? – Matt Burland Sep 25 '13 at 17:43
  • Are you sure you are originating from the same UIViewController instance in both cases? Set a breakpoint at the beginning of the code you have above, and when you reach the breakpoint each time, run "po self" in the debugger. Note the memory address of self and compare it when you get there the second time. – bneely Sep 28 '13 at 08:29

2 Answers2

2

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.

iOsDude
  • 36
  • 3
1

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.
adhyeta
  • 26
  • 3