I have a small iPhone app, which uses a navigation controller to display 3 views (here fullscreen):
First it displays a list of social networks (Facebook, Google+, etc.):
Then it displays an OAuth dialog asking for credentials:
And (after that, in same UIWebView
) for permissions:
Finally it displays the last view controller with user details (in the real app this will be the menu, where the multiplayer game can be started):
This all works well, but I have a problem, when the user wants to go back and select another social network:
The user touches the back button and instead of being displayed the first view, is displayed the second one, asking for OAuth credentials/permissions again.
What can I do here? Xcode 5.0.2 shows a very limited choice for segues - push, modal (which I can't use, because it obscures navigation bar needed for my game) and custom.
I am an iOS programming newbie, but earlier I have developed an Adobe AIR mobile app and there it was possible to 1) replace view instead of pushing and 2) remove an unneeded view from navigation stack.
How to do the same in a native app please?
To expand on the various segues above, this is my solution. It has the following advantages:
Segue Code:
- (void)perform {
// Grab Variables for readability
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
UINavigationController *navigationController = sourceViewController.navigationController;
// Get a changeable copy of the stack
NSMutableArray *controllerStack = [NSMutableArray arrayWithArray:navigationController.viewControllers];
// Replace the source controller with the destination controller, wherever the source may be
[controllerStack replaceObjectAtIndex:[controllerStack indexOfObject:sourceViewController] withObject:destinationController];
// Assign the updated stack with animation
[navigationController setViewControllers:controllerStack animated:YES];
}