How do I set a property on a custom view instantiated from a XIB

后端 未结 3 482
逝去的感伤
逝去的感伤 2021-01-29 01:22

I am just trying to get my head around MVC in Objective C and IOS but am having a problem I\'m hoping someone can help me with.

I have created a custom view (created as

3条回答
  •  孤独总比滥情好
    2021-01-29 01:45

    Your custom view's properties (as opposed to its outlets) can only be set in code unless you create an IB plugin for it.

    Your other subviews can be accessed easily if you create an outlet for each of them in your controller. The view outlet is there as the primary view of that view controller. There is nothing preventing you creating additional outlets to other views/controls. Yu would just need to subclass the view controller and add the outlets as needed. Just remember to set the class name of the controller (in Interface Builder) to that of your custom subclass. That will expose the available outlets for you to connect.

    You'd still need to create an Interface Builder plugin if you want to make your control's custom properties available in IB's inspector palette. Unless you plan to reuse it frequently in other applications or make it available to others, it's probably easiest just to set the properties in your source code.

提交回复
热议问题