I’m trying to use a UIView from a XIB to display in a sub view container in another view
controller. This is how I try to do display the subView in in MainViewController.h:
@property (nonatomic, strong) UIView *subView;
MainViewController.m:
UIViewController* nameController = [[UIViewController alloc] initWithNibName:@"NamesViewController" bundle:nil];
subView = [nameController view];
[self.view addSubview:subView];
But I get this error:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x688e580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key textField.'
Is there something I am doing wrong or have I missed something?
I made a the NamesViewController class with xib, put a textfield in the view, now trying to use the view from this xib as subview.
You should be allocating
NamesViewControllerrather than a “plain”UIViewController:Otherwise, any attempt to connect
IBOutlets would result in a crash. Of course I’m only assuming that the NIB name matches the controller’s name; if it does not, you need to use the correct name.