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.
Existing Posts:
Using xib object inside another xib
How to use a xib and a UIView subclass together?
I have already:
This results in a blank view showing up when I build the application.
I then tried what one of the above posts said to do which was override CustomView's initWithDecoder method and adding the following:
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
UIView *mainView = [subviewArray objectAtIndex:0];
[self addSubview:mainView];
This unfortunately was resulting in the following error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<UIView 0x548ff00> setValue:forUndefinedKey:]:
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.
Not sure what I missed from those previous posts, but I'd appreciate any guidance! Thanks!
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<UIView 0x548ff00> setValue:forUndefinedKey:]:
Reason for the above error
normally comes due the failure of the connections in the Interface Builder
, that is the UIViewController
object with the corresponding objects in the implementation class. Please check your all connection in the Interface Builder
. Also verify the file owner in the xib
file.
I hope this will solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With