2012-10-04 15 views
0

使用Cordova 2.1.0進行IOS應用程序開發。 我已經出發,按照MainViewController.m文件我shouldStartLoadWithRequest功能:AppDelegate.m文件中的函數未從MainViewController.m文件調用

- (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調用:resetBadgeCount」;

但resetBadgeCount是存在於AppDelegate.m文件中的函數,每當shouldStartLoadWithRequest函數被調用,它給出了這樣的錯誤:

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

所以,我應如何改變這樣的錯誤抑制代碼和resetBadgeCount功能是成功的調用。

回答

1

此刻你告訴MainViewController嘗試執行選擇器。這就是爲什麼它說:

- [MainViewController resetBadgeCount]:無法識別的選擇...

嘗試改變[自performSelector:...]至[[[UIApplication的sharedApplication]委託] performSelector:...]