在Cocoa Touch中编程切换视图 [英] Programatically Switching Views in Cocoa Touch
问题描述
如何在iPhone应用程序中以编程方式更改屏幕上的视图?
How would one change the view on the screen programatically in an iPhone app?
我已经能够创建导航视图,并以编程方式推送/这个行为,但是如果我想简单地改变当前的视图(不使用UINavigation控制器对象),什么是最简单的方法来实现这个?
I've been able to create navigation view's and programatically push/pop them to produce this behaviour, but if I wanted to simply change the current view (not using a UINavigation controller object), what is the neatest way to achive this?
一个简单的例子,想象一个带有单个按钮的应用程序,当按下时会显示一个新的视图,或者根据一些内部状态变量显示多个视图中的一个。
A simple example, imagine an application with a single button, when pressed will display a new view, or possibly one of multiple views depending on some internal state variable.
我还没有看到任何示例,尝试这样做,我似乎不足够了解UIViewController / UIView对象之间的关系和初始化过程,以achive这个程序。
I have yet to see any examples that attempt to do this, and I dont seem to understand enough about the relationships and initialisation procedure between UIViewController/UIView objects to achive this programatically.
推荐答案
我使用 presentModalViewController:animated:
从我的主窗口的 UIViewController
中调出一个设置视图,然后当用户在设置视图中按下done时,我会在设置视图中调用 dismissModalViewControllerAnimated:
,返回父视图:
I use presentModalViewController:animated:
to bring up a settings view from my main window's UIViewController
and then when the user presses "done" in the settings view I call dismissModalViewControllerAnimated:
from the settings view (reaching back to the parent view) like this:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
这篇关于在Cocoa Touch中编程切换视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!