2
votes

I'm calling UINavigationController's popToViewController selector, but it is having no effect. The app doesn't crash or freeze, all of the touch elements on the current viewcontroller stay as is.

See the screenshot below. I'm getting no noticeable errors in execution or console, except for the fact that nothing happens.

Things I have considered:

  • Am I on the main thread? Yes, I have ensured this with the performSelectorOnMainThread call at the top of my screenshot.
  • Is the desired viewcontroller already pushed? Yes, you can see this is true in the debug panel of the screenshot. mLoginViewController is in there.
  • Before I try to popTo, am I in a presented modal viewcontroller? No, this is happening at a stage when nothing has been presented.
  • Are the alerts I call at various places part of the problem? Quite possibly -- maybe they are causing the current viewcontroller to not be done displaying?

Screenshot of XCode showing execution halted right before attempting to popTo

Note that at this point in the execution, sometimes the code on lines 263-270 has just been run, which clears the root nav controller's viewControllers array. This means that the currently displayed viewcontroller on the screen is no longer even in the array. Could that be messing up the popTo?

Similar questions:

I'm running XCode 5.0 (5A1413), compiling and running on an iPhone 5 with iOS 7.2.

2

2 Answers

1
votes

Could you try this ?

 [self.mRootController popToRootViewControllerAnimated:NO];

and self notation is important. :)

1
votes

Check the return result from the popToViewController:animated: method - that will return an array of the view controllers the nav controller popped off the stack to reach yours. If it's nil, that means it isn't finding the controller it is looking for. If it contains the correct result, then it would indicate the nav controller thinks it is doing what you ask and the problem is elsewhere.

Is it possible there is code in your CXLoginViewController that responds to viewWillAppear:/viewDidAppear: and changes the nav stack? Do you have something in your custom navigation controller that might not be implementing the method popToViewController:animated: correctly (this has happened to me in the past)?

If the alert you are referring to is the one on line 235, right after the performSelectorOnMainThread: call, it is possible that is causing some problems. performSelectorOnMainThread enqueues that method (represented by the selector) to be called by the run loop. Messing with the UI immediately after calling that could have issues - have you tried taking that alert out?