0

ClientViewController.mmクラスのメソッドを呼び出そうとしていますが、次のエラーが発生し続けます:キャッチされない例外が原因でアプリを終了しています

'NSInvalidArgumentException', reason: '+ [ClientViewController TestMethod]: 
 unrecognized selector sent to class 

インターフェイスを実装する別のクラスがあります。

void AppleRecognitionStatusObserver::onRecognitionStatusChanged
                                       (RecognitionStatus newStatus) {
    switch(newStatus) {
        case kInProgress:
            [ClientViewController TestMethod];
            break;
        ....etc
    }
}

別のC++クラスからClientViewControllerメソッドを呼び出すにはどうすればよいですか?

クライアントビューコントローラー.h

//imports UIKit etc
@interface ClientViewController : UIViewController <AVAudioRecorderDelegate>{
    IBOutlet UIButton *recoButton;
    // some other buttons
}
@end

// and the .mm
//#imports....
@interface ClientViewController ()
@end
@implementation ClientViewController
-(void)TestMethod{
    outLabel.text = @"Has been called!";
}
4

1 に答える 1

0

ClientViewController.mにtestMethodのメソッド実装があることを確認する必要があります。次のようになります。

+(void)TestMethod {
    // some code here
}

ClientViewController.hには、次のような一致するヘッダー宣言が必要です。

+(void)TestMethod;

クラスメソッドの代わりにインスタンスメソッドが必要な場合は、次のように+を-に変更してください。

-(void)TestMethod {
    // some code here
}

-(void)TestMethod;
于 2013-03-13T00:12:53.360 に答える