0

I created a custom notification view (UIView Subclass) in a XIB file. However, I want to have multple types (i.e. one would have one UILabel, another would have 2 UILabels for Title and Subtitle, etc.)

I do this a lot in UITableViewCells using prototypes and cell identifiers, and was wondering if it is possible to do this in one XIB file, and just call the actual view I want to use for the appropriate notification type.

Here is a screenshot of the XIB file I have so you can see what I mean:

enter image description here

JimmyJammed
  • 9,598
  • 19
  • 79
  • 146
  • Of course it's possible. Can you explain what the problem is? If you know how to load a _.xib_ file and pull out a top-level view, then you know how to load a _.xib_ file and pull out three top-level views. But why not have multiple _.xib_ files and just load the _.xib_ file you want, depending on the circumstances? – matt Nov 07 '14 at 23:33
  • Mainly I was hoping to have all variations of the notification view in one xib file for easier maintenance, less files, etc. – JimmyJammed Nov 07 '14 at 23:45
  • Using the above image as an example of my ONE xib file, how would you load the xib using only ONE of those 3 views? I don't see a way to set a 'identifier' on each of those views. – JimmyJammed Nov 07 '14 at 23:48
  • Oh, that's the least of your worries. When you load the xib, you get an array of the top-level objects. The 3 views are top-level objects so now you have all three of them. Figuring out which is which is up to you, but there are lots of ways to do that; after all, they are different from one another. You could even add an identifier property and set it in the nib for each of them. - Nevertheless I can't help feeling that you'd be happier using three nibs instead of one. I could be wrong of course. – matt Nov 08 '14 at 00:33
  • @matt - Yeah I think the way Xcode is currently setup, multiple XIBs is the best option. I just thought it would be nice to use XIBs in a similar fashion to UITableView Prototype cells, allowing multiple views in one nicely packaged XIB. Thanks! – JimmyJammed Nov 12 '14 at 01:52

0 Answers0