开发者

Connecting one Interface Builder view to multiple variables / dynamic creation

开发者 https://www.devze.com 2022-12-21 03:47 出处:网络
I have created a custom view with Interface Builder and defined its IBOutlet variable within my ViewController.

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 开发者_如何学Goall 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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消