0

IOS アプリの開発には Cordova 2.1.0 を使用します。MainViewController.m ファイルに shouldStartLoadWithRequest 関数として次のものがあります。

- (BOOL)webView:(UIWebView *)webView2 
shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    NSLog(@"shouldStartLoadWithRequest function");

    // Intercept custom location change, URL begins with "js-call:"
    if ([[[request URL] absoluteString] hasPrefix:@"js-call:"]) {

        // Call the given selector
        [self performSelector:NSSelectorFromString(@"resetBadgeCount")];

        // Cancel the location change
        return NO;
    }

    // Accept this location change
    return YES;

}

問題は、私の index.html には次のようなものがあります:- window.location = "js-call:resetBadgeCount";

しかし、resetBadgeCount は AppDelegate.m ファイルに存在する関数であり、 shouldStartLoadWithRequest 関数が呼び出されるたびに、次のエラーが発生します。

-[MainViewController resetBadgeCount]: unrecognized selector sent to instance 0x199db0

では、エラーが抑制され、resetBadgeCount 関数が正常に呼び出されるように、コードをどのように変更すればよいでしょうか。

4

1 に答える 1

1

現時点では、MainViewController にセレクターを実行するように指示しています。それが、次のように言っている理由です。

-[MainViewController resetBadgeCount]: 認識されないセレクター...

[self performSelector:...] を [[[UIApplication sharedApplication] delegate] performSelector:...] に変更してみてください

于 2012-10-04T05:36:00.510 に答える