Search code examples
iphoneiosipadios5

iOS custom views in xib files


I usually create my custom views programatically and have them intended to be initialised programatically as well with custom init methods (e.g. initWithFrame:SomeParam:OtherParam). Is it possible to use such custom views in combination with a xib file? That is, having a parent xib file which has various of these custom views as subviews in which these subviews may need to use a different init method?


Solution

  • If you add custom views into a xib file, you can't use a custom initializer. They will all be initialized using initWithCoder.

    Typically you'd do any set up in a common method called from there, or in awakeFromNib.

    If you need to set any custom properties on your view which originate from outside it, do it in viewDidLoad of your view controller.