Ben Wheeler
Ben Wheeler

Reputation: 7384

popToViewController not working

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:

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.

Upvotes: 2

Views: 3491

Answers (2)

RyanR
RyanR

Reputation: 7758

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?

Upvotes: 1

Burcu Geneci
Burcu Geneci

Reputation: 85

Could you try this ?

 [self.mRootController popToRootViewControllerAnimated:NO];

and self notation is important. :)

Upvotes: 1

Related Questions