Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble loading custom view from xib in another xib
    primarykey
    data
    text
    <p>Apologies because I see people have asked questions like this before. However, I haven't had much luck following the instructions. I'm interested in creating a custom view with a xib file and reusing it in another view controller's xib file.</p> <p>Existing Posts:</p> <p><a href="https://stackoverflow.com/questions/5095359/using-xib-object-inside-another-xib">Using xib object inside another xib</a></p> <p><a href="https://stackoverflow.com/questions/4071738/how-to-use-a-xib-and-a-uiview-subclass-together">How to use a xib and a UIView subclass together?</a></p> <p>I have already:</p> <ul> <li>Created a custom xib file (let's call it CustomView.xib), and corresponding .h and .m class files</li> <li>Set the File's Owner of the xib file to CustomView</li> <li>Created a top level UIView with other views as children (UILabel's etc) <ul> <li>NOTE this has a child UIView which is a custom view written in code as well</li> </ul></li> <li>Wired up the IBOutlets</li> <li>Created a ViewController.xib file</li> <li>Added a UIView, set the class to CustomView and also wired that up</li> </ul> <p>This results in a blank view showing up when I build the application.</p> <p>I then tried what one of the above posts said to do which was override CustomView's initWithDecoder method and adding the following:</p> <pre><code>NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil]; UIView *mainView = [subviewArray objectAtIndex:0]; [self addSubview:mainView]; </code></pre> <p>This unfortunately was resulting in the following error:</p> <pre><code>Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[&lt;UIView 0x548ff00&gt; setValue:forUndefinedKey:]: </code></pre> <p>I thought this might be because I didn't set the top level view in CustomView.xib to be of class CustomView. So I then changed it to CustomView, and then things went into infinite recursion. Which makes sense since it's just reloading itself over and over again.</p> <p>Not sure what I missed from those previous posts, but I'd appreciate any guidance! Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload