objective-c - AppDelegate.m 文件中的函数未从 MainViewController.m 文件调用

标签 objective-c ios xcode cordova

使用 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/

相关文章:

ios - 如何访问导航 Pane (左 Pane )中创建的文件夹的路径?

快速获取当前设备在 wifi 和蜂窝网络中的 IP 地址

objective-c - OSX 10.10 中的 NSSplitViewController 使用 Xcode 6

ios objective-c 常量 CGFloat *

ios - 将点击手势从 UIView 传递到底层 AVPlayer

objective-c - 使用 AVPlayer 播放加密视频

ios - 在 MPMoviePlayerController 之上添加 View

ios - Objective-C - 类实例在哪里声明?

ios - 如何让 AVPlayer 立即出现而不是在视频结束后出现?

ios - 景观应用 Xcode 5/iOS 7