Endless recursive calls to initWithCoder when instantiating xib in storyboard

后端 未结 2 682
孤城傲影
孤城傲影 2021-01-12 18:48

In order to re-use a certain subview throughout my application (which is storyboard based), I decided to build the subview as a nib, and load it in. To do this, I have done

2条回答
  •  花落未央
    2021-01-12 19:16

    Did you happen to set the View's "Custom Class" in your .xib file to "Widget"?

    That would explain the behaviour you're seeing, because initWithCoder: is the initializer for all things loaded from a xib:

    1. Your parent view, which contains a Widget object, is loaded from the xib
    2. The Widget's initWithCoder: method gets called, and tries to load the Widget xib
    3. The Widget xib contains a UIView with the Custom Class "Widget", so again, a Widget object is being initialized with initWithCoder:, etc.

    If that is indeed the case, all you have to do is remove the "Custom Class" entry for the UIView in your Widget's xib.

提交回复
热议问题