when using loadNibNamed why do we have to use 'first'? Don't we want to decouple different entities of our source code? [duplicate]

旧城冷巷雨未停 提交于 2019-12-25 08:25:12

问题


For example:

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)

EDIT

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?


回答1:


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.

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).



来源:https://stackoverflow.com/questions/41553861/when-using-loadnibnamed-why-do-we-have-to-use-first-dont-we-want-to-decouple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!