在Cocoa Touch中以编程方式切换视图 [英] Programmatically Switching Views in Cocoa Touch

查看:64
本文介绍了在Cocoa Touch中以编程方式切换视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iPhone应用程序中以编程方式更改屏幕上的视图?

How would one change the view on the screen programmatically in an iPhone app?

我已经能够创建导航视图并以编程方式将其推入/弹出来产生这种行为,但是如果我想简单地更改当前视图(不使用UINavigation控制器对象),那么实现这一目标的最捷径是什么? ?

I've been able to create navigation view's and programmatically 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 achieve 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对象之间的关系和初始化过程似乎还不够了解,无法以编程方式实现这一目标.

I have yet to see any examples that attempt to do this, and I don't seem to understand enough about the relationships and initialisation procedure between UIViewController/UIView objects to achieve this programmatically.

推荐答案

我使用presentModalViewController:animated:从主窗口的UIViewController调出设置视图,然后当用户在设置视图中按完成"时, 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屋!

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