Using Xcode and Interface Builder to Create Prototype Views

I am creating an NSView, which is a kind of collection view, but instead of a table or grid, it will be a graph editor (similar to a quartz composer).

The problem I am facing right now is that I would like to load the prototype views (for nodes) from the xib file. Like UITableView and UICollectionView, you can prototype cells in Interface Builder. But how are these objects then created in multiple instances?

How does UITableViewController et al. Achieve this?

The solutions I thought of:

  • Copy the view, but NSView does not support NSCopying out of the box. This seems the most logical so far. This also seems like the only option if you want to save the NSView in the storyboard , not in xib .
  • Download the tip, and then send [nib instantiateNibWithOwner:self topLevelObjects:nil] several times.
  • NSView supports NSCoding , but using this is more like a hack.

Any ideas?

I am developing a Mac OS X application, not an iOS application.

+5
source share
1 answer

You are right, the implementation of NSCopying through NSCoding really looks like a hack, but this is the fastest and most reliable way to encode it.

Copy NSView to cocoa / objective-c "linked copy / code response"

You can put your presentation on the storyboard as the top level object of any scene. Make sure you have an output from the controller / loader of this scene. You can probably pack it in NSData and just stick with it for every “copy” you want to make / unarchived.

-1
source

All Articles