【发布时间】:2024-01-21 05:27:01
【问题描述】:
查看其他一些问题,这是我在实现自定义键盘的视图的 .m 中实现的代码。
- (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;
}
下面是出现的错误。
* 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:该类与键视图的键值编码不兼容。”
当我将笔尖加载到实际的视图控制器中时,它可以正常工作。但是,如上所述,当我尝试将其加载到另一个视图中时,它不起作用。
另外,在 nib 中,我将文件所有者的类设置为 UIViewController 并将其附加到主视图,因为这是另一个 SO 问题所指示的。我不确定是否需要修改它,因为我将自定义视图添加到另一个视图而不是 viewc 控制器中。
谢谢
编辑:
实现键盘的视图.h
@interface EquationTextField : UIView <KeyInput> {
FormulaKeyboard *keyboard;
}
@property (readwrite, retain) UIView *inputView;
@end
【问题讨论】:
标签: objective-c ios view uiview