xcode iOS 编译错误:“CDViewController”没有可见的@interface 声明了选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18485134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:44:36  来源:igfitidea点击:

iOS compile error: No visible @interface for 'CDViewController' declares the selector

iosxcode

提问by Timo

Since I switched my iOS project to ARC, I keep getting this compiler error:

自从我将 iOS 项目切换到 ARC 以来,我不断收到此编译器错误:

No visible @interface for 'CDViewController' declares the selector 'setUseAgof:'

“CDViewController”没有可见的@interface 声明了选择器“setUseAgof:”

In this line:

在这一行:

[self.viewController setUseAgof:false];

In this file:

在这个文件中:

AppDelegate.m

AppDelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"
#import <Cordova/CDVPlugin.h>
#import "NSString+MD5.h"

@implementation AppDelegate

@synthesize window, viewController;

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    // (...)
    [self.viewController setUseAgof:false]; // <-- HERE
    // (...)

    return YES;
}

@end

Although the method is definitely defined:

虽然方法是明确定义的:

MainViewController.h

主视图控制器.h

#import <Cordova/CDVViewController.h>
#import <ADTECHMobileSDK/ADTECHMobileSDK.h>

@interface MainViewController : CDVViewController <ATInterstitialViewDelegate>{
    ATInterstitialView *interstitial;
}
- (void)setUseAgof:(BOOL)useAgofParam;
@end

@interface MainCommandDelegate : CDVCommandDelegateImpl
@end

@interface MainCommandQueue : CDVCommandQueue
@end

MainViewController.m

主视图控制器.m

#import "MainViewController.h"

@interface MainViewController()
    - (void)setUseAgof:(BOOL)useAgofParam;
@end

@implementation MainViewController

BOOL useAgof = true;

- (void)setUseAgof:(BOOL)useAgofParam
{
    NSLog(@"1.) Setting useAgof = %d", (int)useAgofParam);
    useAgof = useAgofParam;
}

I don't get it. What's wrong?

我不明白。怎么了?



Update:

更新:

AppDelegate.h

AppDelegate.h

#import <UIKit/UIKit.h>
#import <Cordova/CDVViewController.h>
#import <INFOnlineLibrary/INFOnlineLibrary.h>

@interface AppDelegate : NSObject <UIApplicationDelegate>{}

@property (nonatomic, strong) IBOutlet UIWindow* window;
@property (nonatomic, strong) IBOutlet CDVViewController* viewController;

@end

采纳答案by Amar

viewControllerseems to be declared as pointer of CDVViewController. You are calling a method which is part of MainViewControllerthe class derived from CDVViewController. Method being called is part of derived class and not the base class, hence make viewControllerpointer of MainViewControllerinstead.

viewController似乎被声明为的指针CDVViewController。您正在调用一个方法,该方法是MainViewControllerCDVViewController. 被调用的方法是派生类的一部分而不是基类,因此使用viewController指针 MainViewController代替。

回答by Mike Kwan

Make sure the viewControllerproperty in your AppDelegatehas a type of CDVViewController *rather than UIViewController *.

确保viewController您的属性AppDelegate具有类型CDVViewController *而不是UIViewController *