2013-05-21 64 views
0

我已經從this下載了一個使用自定義鍵盤的示例項目。在ios中使用自定義鍵盤的問題

它完美的作品。

但是,當我用在我的項目則返回錯誤 - -[UIView playKeyboardClick]: unrecognized selector sent to instance 0x71d6390

了什麼我做了 -

我增添了新的viewcontoller文件NerdKeyboard.hNerdKeyboard.mUIView文件NerdKeyboardView.hNerdKeyboardView.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];

什麼馬拋出問題是什麼?

任何建議,將不勝感激。

+1

它看起來像你的視圖控制器的視圖是一個普通的'UIView'而不是'NerdKeyboardView'。確保你在xib中正確設置了類。 – omz

回答

1

如果連接不正確或操作系統無法找到定義的功能,則會出現此類錯誤。如果您使用的是xib,請檢查連接是否正確。否則請檢查功能setText是書面正確。可能會有一個問題與外殼或功能的名稱。

+0

連接沒有問題,當我調試它的錯誤拋出謊言'[(NerdKeyboardView *)self.view playKeyboardClick];' – NAZIK

+0

+1的建議 – NAZIK

+0

在playkeyboardclick方法中放置一個斷點,並調試,看看是否控制正在進入它..其他有一些問題與self.view..maybe它爲零 –