简体   繁体   中英

UINavigationController and presenting a modal controller

If got a rootViewController which display's a UIScrollView full screen. When I tap the UIScrollview, I want to flip the screen and display a settings screen (which also has a second screen, the reason for the navigationController).

I am able to display the settings screen by using the following code in my rootViewController: self.navController = [[UINavigationController alloc] initWithRootViewController:self.settingsViewController];

and than: [self.navController pushViewController:self.settingsViewController animated:YES];

My question is: When I'm done in my settings view, how do I return back to the rootViewController, so the controller class in which I have created the navigation Controller and is therefore not on the stack.

I've adopted Apple's solution which they use in the Metronome example .

I'm setting the settingsViewController as the rootViewController for a navigationController. Than I display the navigationController using:

[self presentModalViewController:navController animated:YES];

As per apple's example, I've created a settingsViewControllerDelegate interface which the rootViewController adopts. The interface is not complicated, just a delegate instance var and a callback method (settingsViewControllerDidFinish) which needs to be implemented by rootViewController. In that methode you call:

[self dismissModalViewControllerAnimated:YES];

This way I'm able to have a couple of settings-screens using a navigationController and I'm able to return out of the navigationController back to the rootViewController.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM