UINavigationController and presenting a modal controller

≡放荡痞女 提交于 2019-12-19 12:08:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5660685/uinavigationcontroller-and-presenting-a-modal-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!