使用Cordova 2.1.0进行IOS应用程序开发。 我在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函数。
答案 0 :(得分:1)
此时您正在告诉MainViewController尝试执行选择器。这就是为什么它说:
- [MainViewController resetBadgeCount]:无法识别的选择器...
尝试将[self performSelector:...]更改为[[[UIApplication sharedApplication]委托] performSelector:...]