我如何使视图控制器与视图之间建立连接?(How do I make outlet connections from my view controller to my views?)

编程入门 行业动态 更新时间:2024-10-16 00:24:38
我如何使视图控制器与视图之间建立连接?(How do I make outlet connections from my view controller to my views?)

您好,我正在尝试学习如何为iPhone编写应用程序。

我正在用一本书来指导我。 不幸的是,这本书是在界面生成器被集成到Xcode之前编写的。

所以现在我试图做一个简单的应用程序,在三个视图之间切换。

我想将文件所有者的插座连接到另一个视图控制器。 在本书中,它表示我假设要从文件所有者控件拖到视图控制器的文档窗口中。 但是在新的Xcode中,我的其他视图/视图控制器只有iPhoneStoryboard和Xib文件。 那么如何在视图控制器之间连接插座?

有谁能帮我吗?

PS:必要的代码已被写入。

Hi I'm trying to learn how to write apps for the iPhone.

I'm using a book to guide me. Unfortunately the book is written before interface builder was integrated in to Xcode.

So now I'm trying to make a simple app that switches between three views.

I want to connect an outlet from File's Owner to another view controller. In the book it says that I'm suppose to Control-drag from File's Owner to the view controller, in the Document window. But in the new Xcode there's only the iPhoneStoryboard and the Xib files for my other views/viewcontrollers. So how do you connect outlets between view controllers?

Could anybody please help me?

PS: the necessary code have already been written.

最满意答案

文件所有者只是在加载nib时指定为所有者的对象的代理,通常是应用程序本身或视图控制器。 如果在nib A中有一个视图控制器,它从nib B加载其视图,则可以将nib B中的任何内容连接到B中的文件所有者代理,并且在加载nib时将它从A连接到视图控制器。 除此之外,您不能将一个笔尖中的物体连接到另一个笔尖上的插座。 (可以创建其他代理对象,如文件所有者,但如果您已准备好这样做,则不会问这个问题。)

File's Owner is just a proxy for the object that's specified as the owner when the nib is loaded, usually either the application itself or a view controller. If you have a view controller in nib A that loads its view from nib B, then you can connect anything in nib B to the File's Owner proxy in B and it'll be connected to the view controller from A when the nib is loaded. Other than that, you can't connect objects in one nib to outlets in another. (It's possible to create other proxy objects like File's Owner, but if you were ready to do that you wouldn't be asking this question.)

更多推荐

本文发布于:2023-07-07 04:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   控制器   outlet   connections   controller

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!