为什么我必须在自定义 NIB / XIB 中连接 IBOutlet 两次?
我创建了一个自定义 myViewController 类,它具有默认的视图,以及子视图的 IBOutlet (topleftView)。
我创建了一个自定义 NIB/XIB 文件来加载此 myViewController.xib。在 XIB 文件中,我已将文件所有者设置为 myViewController,并将 UIViewController 标识类设置为 myViewController。
我的问题是为什么我必须从子视图中的 IBOutlet 连接并绘制对文件所有者和界面生成器中的 UIViewController 的引用?
只是想弄清楚这个问题,因为这是我第一次创建自定义 NIB/XIB。我通常只是在主窗口中完成所有操作,但我的应用程序变得太大,所以我想将事情分散开。
如果我在同一个 nib 文件中没有将一个 IBOutlet 与 UIViewController 和文件所有者建立多个连接,则会因 _EXC_BAD_ACCESS_ 错误而崩溃。
I have created a custom myViewController class and it has the default view, as well as an IBOutlet (topleftView) to a subview.
I have created a custom NIB/XIB file to load this myViewController.xib. Inside the XIB file I have set the file owner to myViewController and set the UIViewController identity class to myViewController as well.
My question is why do I have to hook up and draw a reference from the IBOutlet in the subview to both the file owner AND the UIViewController in interface builder?
Just trying to get my head around it since this is the first time I'm creating a custom NIB/XIB. I usually just did everything in MainWindow but my application is getting too large so I want to spread things out.
If I don't have these multiple connections for the one IBOutlet to both the UIViewController and File Owner in the same nib file I crash with _EXC_BAD_ACCESS_ errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你在这里做什么。我认为这就是问题所在。你的 XIB 顶层有多少项?它应该只是文件的所有者,第一个如果这里有另一个控制器对象,那就是你的问题了。
这部分是正确的。要将自定义 UIViewController 连接到 XIB,请关注“文件所有者”,转到“身份检查器”,然后在“类”字段中查看“类身份”下。将其设置为'myViewController'(或任何您命名的名称)
此时,您应该为您设置的每个出口执行 1 次 Ctrl 拖动操作。
I'm not sure what you are doing here. I think this is where the problem is. How many items do you have on the top level of your XIB? It should just be File's Owner, First Responser and a View. If there is another controller object in here, that's your problem. Get rid of it.
This part is correct. To connect your custom UIViewController to the XIB, clock on your "File's Owner", go to the "Identity Inspector" then look under "Class Identity" at the "Class" field. Set this to 'myViewController' (or whatever you named it).
At this point you should do 1 ctrl-drag from your File's Owner for each outlet you have setup.
简短的回答:你不知道。只需将文件所有者的类设置为 UIViewController 子类的类名即可。
Short answer: You don't. Just set your File's Owner's class to the class name of your UIViewController subclass and you're set.