同じ問題を解決するために他にも多くの質問がありますが、私はカスタムキーボードを使用しているので、少し違う。カスタムキーボードのボタンを押すと「認識できないセレクタがインスタンスエラーに送信されます」
これは、特定のエラーである:
- [EquationTextField element1Pressed:]:23:44.630 rowQuizを[20975:207]認識されないセレクター 2012-01-02 12インスタンス0x4b68ee0に送信アプリの終了によりキャッチされないと例外 'NSInvalidArgumentException'、理由: ' - [EquationTextField element1Pressed:]:インスタンスに送信された認識できないセレクタ0x4b68ee0'
私はビューコントローラ、quizControllerを持っています。 quizControllerの内部は、カスタムビューのtextField(インターフェースビルダーを介して追加された)です。
textFieldをタップすると、別のカスタムビューのformulaKeyboardがキーボードとしてポップアップします。キーボードのボタンを押すと、方法element1Pressed:
が呼び出され、上記のエラーが表示されます。
残数に問題があると言われているので、問題を解決しなかったアプリケーションデリゲートにquizControllerを保持して解放しようとしました。
Interface Builderで間違ったものを作成した可能性もあります。カスタムキーボードの場合、Fileの所有者とメインビューはclassKeyKeyクラスに設定されます。 quizControllerの場合、Fileの所有者はquizControllerに設定され、そのビューにフックされます。
以下は、textFieldのクラスのコードです。
EquationTextField.h
#import <UIKit/UIKit.h>
#import "FormulaKeyboard.h"
@interface EquationTextField : UIView <KeyInput> {
FormulaKeyboard *keyboard;
NSString *lastElement;
}
@property (readwrite, retain) UIView *inputView;
@end
EquationTextField.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;
keyboard.delegate = self;
}
return self;
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
#pragma mark -- KeyInput Protocol Methods
- (void)addElement:(NSString *)elementName {
}
- (void)addCharge:(NSString *)chargeIncrease {
}
- (void) addState:(NSString *)stateName {
}
- (void)deleteCharacter {
}
- (void)dealloc
{
[super dealloc];
}
formulaKeyboard.h
#import <UIKit/UIKit.h>
@protocol KeyInput <UITextInputTraits>
- (void) addElement:(NSString*) elementName;
- (void) addCharge:(NSString*) chargeIncrease;
- (void) addState:(NSString*) stateName;
- (void) deleteCharacter;
@end
@interface FormulaKeyboard : UIView {
id <KeyInput> delegate;
}
@property (nonatomic, retain) id <KeyInput> delegate;
-(IBAction) element1Pressed:(id)sender;
-(IBAction) element2Pressed:(id)sender;
-(IBAction) element3Pressed:(id)sender;
-(IBAction) element4Pressed:(id)sender;
-(IBAction) element5Pressed:(id)sender;
-(IBAction) element6Pressed:(id)sender;
-(IBAction) chargePlusPressed:(id)sender;
-(IBAction) chargeMinusPressed:(id)sender;
-(IBAction) solidSatePressed:(id)sender;
-(IBAction) liquidStatePressed:(id)sender;
-(IBAction) gasStatePressed:(id)sender;
@end
formulaKeyboard.m
ここで何が起こっているappDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
quizController = [[QuizController alloc] initWithNibName:@"QuizController" bundle:nil];
[self.window addSubview:quizController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[_window release];
[quizController release];
[super dealloc];
}
これは、すべてのEquationTextFieldの実装ですか?それは 'element1Pressed:'メソッドを持っていますか? – MyztikJenz
@MyztikJenz 'element1Pressed:'メソッドは、FormulaKeyboardの実装にあります。上記のコードを追加しました。 – Mahir