使用 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函数。
最佳答案
此时,您正在告诉 MainViewController 尝试执行选择器。这就是为什么它说:
-[MainViewController resetBadgeCount]:无法识别的选择器...
尝试将 [selfperformSelector:...] 更改为 [[[UIApplicationsharedApplication]delegate]performSelector:...]
关于objective-c - AppDelegate.m 文件中的函数未从 MainViewController.m 文件调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12720837/