我已经从this链接下载了一个示例项目,以使用自定义键盘。
它完美地工作。
但是,当我在项目中使用它时,它会返回错误--[UIView playKeyboardClick]: unrecognized selector sent to instance 0x71d6390
我做了什么-
我为NerdKeyboard.h
和NerdKeyboard.m
添加了新的viewcontoller文件UIView
和NerdKeyboardView.h
和NerdKeyboardView.m
文件。我从示例项目中粘贴了相同的代码,并在xib中进行了相同的设计。
但是,当我单击NerdKeyboard.xib文件中的按钮时,它将返回错误Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView playKeyboardClick]: unrecognized selector sent to instance 0x71d6390'*** First throw call stack:(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2769 0x10e3705 0x172c0 0x17258 0xd8021 0xd857f 0xd76e8 0x46cef 0x46f02 0x24d4a 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x1ebd 0x1de5)libc++abi.dylib: terminate called throwing an exception
如果您想查看代码:
NerdKeyboard.h
#import <UIKit/UIKit.h>
@interface NerdKeyboard : UIViewController
@property (nonatomic, weak) id delegate;
- (IBAction)keyPress:(id)sender;
- (IBAction)doneEditing:(id)sender;
@end
NerdKeyboard.m
#import "NerdKeyboard.h"
#import "NerdKeyboardView.h"
@implementation NerdKeyboard
- (IBAction)keyPress:(id)sender
{
[(NerdKeyboardView *)self.view playKeyboardClick];
if (self.delegate && [self.delegate respondsToSelector:@selector(setText:)]) {
NSString *oldText = [self.delegate text];
NSString *thisKey = [[(UIButton *)sender titleLabel] text];
[self.delegate performSelector:@selector(setText:) withObject:[oldText stringByAppendingString:thisKey]];
} else if (self.delegate && [self.delegate respondsToSelector:@selector(nerdKeyPress:)]) {
[self.delegate performSelector:@selector(nerdKeyPress:) withObject:[[(UIButton *)sender titleLabel] text]];
}
}
- (IBAction)doneEditing:(id)sender
{
if (self.delegate && [self.delegate respondsToSelector:@selector(resignFirstResponder)]) {
[self.delegate performSelector:@selector(resignFirstResponder)];
}
}
@end
NerdKeyboardView.h
#import <UIKit/UIKit.h>
@interface NerdKeyboardView : UIView <UIInputViewAudioFeedback>
- (void)playKeyboardClick;
@end
NerdKeyboardView.m
#import "NerdKeyboardView.h"
@implementation NerdKeyboardView
- (BOOL)enableInputClicksWhenVisible {
return YES;
}
- (void)playKeyboardClick
{
[[UIDevice currentDevice] playInputClick];
}
@end
当我调试它时,错误被抛出在
[(NerdKeyboardView *)self.view playKeyboardClick];
行中可能是什么问题?
任何建议,将不胜感激。
最佳答案
如果连接不正确或操作系统无法找到定义的函数,则会出现这种错误。如果您使用的是xib,请检查连接是否更正确。否则请检查函数setText是否正确编写。也许大小写或功能名称有问题。