在一个 UIViewController 中的 UIViews 之间交换 [英] Swapping between UIViews in one UIViewController

查看:21
本文介绍了在一个 UIViewController 中的 UIViews 之间交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在寻找解决 iPhone SDK 的方法,我已经学习了一些很好的教程,但我目前正在尝试寻找一些简单的解决方案.

I'm still finding my way around the iPhone SDK, I've followed some good tutorials but I am trying to find some simple solutions for the time being.

现在我想创建一个共享相同 UIViewController 的简单应用.

Right now I want to knock up a simple app that will share the same UIViewController.

我在 Interface Builder 中创建了多个视图,并在 Inspector 中为它们指定了唯一的名称(身份视图 - Interface Builder 身份).

I have created multiple views in Interface Builder and given them unique names in the Inspector (Identity view - Interface Builder Identity).

假设我已经放置了一个按钮并编写了一个在按下按钮时调用的操作.我的简单问题是在 xcode 中,如何以编程方式调用其他视图之一?

Assuming I've placed a button and written an action called when the button is pressed. My simple question is within xcode, how do I call the one of the other views programmatically?

非常感谢

推荐答案

我建议您在尝试控制多个视图时使用多个视图控制器.将它们包装在 UINavigationController 中,让您的生活更轻松.

I would suggest you use multiple view controllers when trying to control multiple views. Wrap them in a UINavigationController to make your life easier.

话虽如此,您希望在主控制器中创建 IBOutlets,并将每个 IBOutlets 连接到您的一个视图.然后,当您准备好时,您可以

With that said, you want to create IBOutlets in your main controller, and hook each one up to one of your views. Then, when you're ready, you can

[view1 removeFromSuperview];
[self.view addSubview: view2];

请注意,这假定您使用第三个单独的视图作为控制器的主视图.

Note, this presupposes you're using a third, separate view as your controller's main view.

这篇关于在一个 UIViewController 中的 UIViews 之间交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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