问题
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 UITableViewCell
s 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