在这种情况下,XIB中的File所有者是什么? [英] What is File’s owner in XIB in this case?

查看:145
本文介绍了在这种情况下,XIB中的File所有者是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了类似的问题很长一段时间了,其中大部分提到了UIViewController的xib内容。 我尝试为我的自定义viewController模型添加一个xib文件,并发现它的Xib文件所有者应该是我的自定义viewController模型的类 - 这是合理的。但是当我为我的UIView模型创建一个xib时情况有所不同 - 示例如下:

I've searched for similar questions for quite a while, most of which mentioned UIViewController's xib stuff. I tried to add a xib file for my custom viewController model,and found that its Xib’s File’s Owner should be my custom viewController model's class--that is reasonable. But why the situation differs when i create a xib for my UIView model-- an example as follows:

我创建了名为KWView的UIView模型(KWView.h和KWView.m)
然后我为这个模型创建xib,初始化为

I create my UIView model which named "KWView"(KWView.h and KWView.m) then i create xib for this model, initializing it by

 KWView *oneView = [[[NSBundle mainBundle] loadNibNamed:@"KWView" owner:nil options:nil ]lastObject];

这个Xib的文件所有者名称是NSObject(然后我尝试其他任何更多,无论如何我选择,它运行顺利),在那里,我选择视图的自定义类为KWView[此xib名为KWView.xib]

This Xib’s File’s Owner name is "NSObject"(then i try any other more,whatever i choose, it runs smoothly),and there, i choose the view’s Custom Class as "KWView"[This xib named "KWView.xib"]

问题是:

1.无论我更改自定义视图的Xib文件所有者名称,它都可以。如果是这样,这个文件的所有者在这里做了什么工作,或说,为什么会发生这种情况?

2.一般来说,我应该设置自定义视图的Xib文件的所有者到我的自定义视图的类或viewController的类,该视图将被添加到哪个?或者只是将其设置为NSObject?

推荐答案

您的问题的答案取决于您打算如何提取视图从笔尖加载时的笔尖。正如你有帮助地向我们展示的那样,你将提取它,如下所示:

The answer to your question depends how you intend to extract the view from the nib at nib-load time. You are going to extract it, as you have helpfully shown us, like this:

KWView *oneView = 
    [[[NSBundle mainBundle] loadNibNamed:@"KWView" owner:nil options:nil]
        lastObject];

这意味着您没有使用所有者:对于此处的任何内容 - 它是 nil 。因此,您可以将nib的文件所有者留在NSObject。

That means you aren't using the owner: for anything here — it is nil. Therefore you can leave the nib's file's owner at NSObject.

文件所有者的目的是允许您在nib中建立视图之间的Action和Outlet连接(或其子视图)和加载时将成为真实所有者的对象 - 如视图控制器(所有者)及其视图(视图控制器的主视图)。但在你的情况下,没有这样的真实所有者,也没有这样的行动或出口连接。

The purpose of the File's Owner is to permit you to establish, in the nib, Action and Outlet connections between the view (or its subviews) and the object that will be the real owner at load time — like a view controller (owner) and its view (the main view of the view controller). But in your case, there is no such real owner and no such Action or Outlet connections.

这篇关于在这种情况下,XIB中的File所有者是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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