0

我已经从这个链接下载了一个使用自定义键盘的示例项目。

它完美地工作。

但是,当我在我的项目中使用它时,它会返回一个错误 --[UIView playKeyboardClick]: unrecognized selector sent to instance 0x71d6390

我做了什么——

我添加了新的viewcontoller 文件NerdKeyboard.hNerdKeyboard.mUIView文件。我从示例项目中粘贴了相同的代码,并在 xib 中进行了相同的设计。NerdKeyboardView.hNerdKeyboardView.m

但是当我单击 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

如果您想查看代码:

书呆子键盘.h

#import <UIKit/UIKit.h>

@interface NerdKeyboard : UIViewController

@property (nonatomic, weak) id delegate;

- (IBAction)keyPress:(id)sender;
- (IBAction)doneEditing:(id)sender;

@end

书呆子键盘.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 

书呆子键盘视图.m

#import "NerdKeyboardView.h"

@implementation NerdKeyboardView

- (BOOL)enableInputClicksWhenVisible {
    return YES;
}

- (void)playKeyboardClick
{
    [[UIDevice currentDevice] playInputClick];
}

@end

当我调试它时,错误被抛出[(NerdKeyboardView *)self.view playKeyboardClick];

可能是什么问题?

任何建议,将不胜感激。

4

1 回答 1

1

如果连接不正确或操作系统无法找到定义的函数,则会出现这种错误。如果您使用的是xib,请检查连接是否更正确。否则检查函数setText是否编写正确。也许可以是大小写或函数名称的问题。

于 2013-05-21T06:33:38.517 回答