![](/img/trans.png)
[英]iOS CoreBluetooth state unsupported when using in iOS custom keyboard
[英]Issues in using custom keyboard in ios
我從下載了一個樣本項目這個鏈接,使用自定義鍵盤。
它運作完美。
但是,當我在項目中使用它時,它返回錯誤-[UIView playKeyboardClick]: unrecognized selector sent to instance 0x71d6390
我做了什么-
我為NerdKeyboardView.h
和NerdKeyboardView.m
添加了新的viewcontoller文件NerdKeyboard.h
和NerdKeyboard.m
和UIView
文件。 我從示例項目中粘貼了相同的代碼,並在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是否正確編寫。也許大小寫或功能名稱有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.