Looking at some of the other questions, this is the code I implemented in the .m of the view implementing the custom keyboard.
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
self.userInteractionEnabled = YES;
[self addGestureRecognizer:
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(becomeFirstResponder)]];
NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:@"FormulaKeyboard" owner:self options:nil];
for (id object in bundle) {
if ([object isKindOfClass:[FormulaKeyboard class]])
keyboard = (FormulaKeyboard *)object;
}
self.inputView = keyboard;
}
return self;
}
Below is the error that showed up.
* Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.’
When I load the nib in an actual view controller, it works fine. However, as evidenced above, it doesn’t work when I try loading it inside another view.
Also, in the nib, I set the file owner’s class to UIViewController and attached it to the main view, since this was what another SO question instructed. I’m not sure if I need to modify this since I’m adding the custom view inside another view and not a viewc controller.
Thanks
EDIT:
.h of view implementing keyboard
@interface EquationTextField : UIView <KeyInput> {
FormulaKeyboard *keyboard;
}
@property (readwrite, retain) UIView *inputView;
@end
Inside the
xibif youctrl+clicktheFile's Owneryou will most likely see that you have aviewoutlet that is connected to the top levelviewobject in thexib.IBOutletin your codeThe reason this works inside a
UIViewControlleris that aUIViewControllerhas a propertyviewwhich gets connected up when loading thexib.A
UIViewsubclass does not normally have a property calledviewtherefore you get an exception.Seems as you are grabbing the item from the top level objects array returned by the
loadNibNamed:owner:options:method you do not need this connection in thexib. Therefore you can disconnect this connection in thexibfile.Alternatively
You could:
File's Ownerclass to the class of your custom view.inputViewanIBOutletinputViewto your custom keyboard in thexibThen just use