使用 loadNibNamed 时为什么我们必须使用“first"?我们不想解耦源代码的不同实体吗? [英] when using loadNibNamed why do we have to use 'first'? Don't we want to decouple different entities of our source code?

查看:25
本文介绍了使用 loadNibNamed 时为什么我们必须使用“first"?我们不想解耦源代码的不同实体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

NSBundle.mainBundle().loadNibNamed("Games-New", owner: nil, options: nil).first

怎么可能有多个视图?!我只从情节提要中拖出一个视图,然后在其中放置一个标签/图像就完成了.或者这是否意味着我可以拖动多个类似容器的视图,而我拖出的第一个视图将是第一个视图?(这将是一个非常糟糕的主意)

How can there possibly be multiple views?! I only drag one view from the storyboard and then put a label/image inside of it and am done. Or does this mean I can drag multiple container-like views and the first view I drag out would be the first or something? (that would be a pretty bad idea)

为什么将事物分组是个好主意?我认为整个想法是解耦不同的元素/视图.这样做是不是正好相反?

Why would it ever be a good idea to group things? I thought the whole idea is to decouple different elements/views. Isn't doing such exactly the opposite?

推荐答案

即使您只将一个视图拖到那里 - 它仍然准备支持 XIB 文件内部的多个视图.

Even though you dragged only one view there - it's still prepared to support multiple views inside on XIB files.

如果您在同一个文件中创建更多视图,您将能够通过使用适当的索引值来选择正确的视图.

If you create more views in the same file, you will be able to pick the correct one by using proper index value.

一个想法是将所有 UITableViewCell 保存在 1 个 XIB 文件中 - 并通过将一个类与您正在寻找的类进行比较来迭代这些类以获得您正在寻找的类.我认为仍然不建议这样做 - 因为将视图保存在单独的 xib 文件中更容易 - 特别是如果有多个人在同一个项目上工作(以避免冲突).

One idea would be to keep all UITableViewCells in 1 XIB file - and iterate over the classes to get the one you are looking for, by comparing a class to the one you are looking for. It's still not recommended in my opinion - since it's easier to keep views in seperated xib files - especially if there are multiple people working on the same project (to avoid conflicts).

这篇关于使用 loadNibNamed 时为什么我们必须使用“first"?我们不想解耦源代码的不同实体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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