UINavigationController并呈现模态控制器 [英] UINavigationController and presenting a modal controller

查看:82
本文介绍了UINavigationController并呈现模态控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一个显示UIScrollView全屏的rootViewController。当我点击UIScrollview时,我想翻转屏幕并显示一个设置屏幕(也有第二个屏幕,导航控制器的原因)。

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).

我能够使用rootViewController中的以下代码显示设置屏幕:

self.navController = [[UINavigationController alloc]
initWithRootViewController:self.settingsViewController];

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

而不是:

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

我的问题是:当我在设置视图中完成后,如何返回rootViewController,所以我在其中创建导航控制器的控制器类,因此不在堆栈中。

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.

推荐答案

我采用了Apple的解决方案他们在节拍器示例中使用它。

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

我将settingsViewController设置为navigationController的rootViewController。比我使用以下方式显示navigationController:

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


[self presentModalViewController:navController animated:YES];

根据apple的例子,我创建了一个settingsViewControllerDelegate接口,rootViewController采用了该接口。接口并不复杂,只需要一个委托实例var和一个需要由rootViewController实现的回调方法(settingsViewControllerDidFinish)。在那个方法中你打电话:

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];

这样我就可以使用navigationController进行几个设置屏幕,我可以返回从navigationController返回到rootViewController。

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.

这篇关于UINavigationController并呈现模态控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆