views:

174

answers:

1

Hi,

I have created a custom view with Interface Builder and defined its IBOutlet variable within my ViewController. Now I would like to instantiate multiple variables of this view, without duplicating the view in Interface Builder and creating its respective IBOutlets. When I connect the view in Interface Builder to multiple reference outlets they all instantiate the same view, but I would like to place multiple views at different positions as subviews. What is the right way to do this ?

A: 

This is very similar to my question Reusable Bits of Interface Designed in IB, which contains working code.

You might not like that solution, though, because it still requires that you place "placeholder" views in the appropriate locations and connect them up (even though their content is copied automatically). In most circumstances, this makes perfect sense: you need to tell your app where to place the views and what outlets they're connected to anyway at some point.

If manually specifying location and outlets seems "wrong" to you, then perhaps your situation would be better addressed by something like an NSCollectionView or an NSMatrix, which will handle placement and organization for you.

andyvn22