iOS开发之报错no visible @interface for XXX declares the selector YYY

在iOS/Xcode开发过程中,出现如下异常信息:

no visible @interface for XXX declares the selector YYY

[图片上传失败...(image-537a76-1523521726866)]

分析原因:

There are lots of reasons it could happen, but generally it’s saying that at the line of code it flags, it doesn’t see any evidence that the selector you are referencing is in the interface of the type it thinks the object has.

有很多原因导致这一情况发生,但是一般而言,发生异常的代码行,指没有在interface接口文件中,找到任何你引用的selector(方法)。有可能是没有在interface进行声明定义,也有可能是字母输入错误。

google搜索时出现很多有关的其他问题:

1、=======问:

在appdelegate.m中创建了一个方法:

-(void)setupTabBarController {
         // details goes here
}

在ABC.m中访问setupTabBarController

已经包括了delegates:

#import "AppDelegate.h"

然后:

AppDelegate *maindelegate = [[AppDelegate alloc] init];
[maindelegate setupTabBarController];

但是报错:

No visible @interface for 'Appdelegate' declares the selector 'setupTabBarController'

不知道怎么搞的。

==========答:

首先你没有在AppDelegate 的.h头文件中定义方法名,说明方法是一个私有方法,无法被外部文件访问.如果是public的方法,需要在头文件中声明

-(void) setupTabBarController;

再者AppDelegate 的创建,AppDelegate 应该是一个单例.你不可再使用如下代码来创建

AppDelegate *maindelegate = [[AppDelegate alloc] init];

改成

AppDelegate *maindelegate = [UIApplication sharedApplication].delegate;

2、=======问

I'm getting No visible @interface for 'NSObject' declares the selector 'viewDidLoad' on the lines:

[super viewDidLoad];

[_viewWeb loadRequest:requestObj];

[super didReceiveMemoryWarning];

UIViewControllerHUB.m

#import "UIViewControllerHUB.h"

@interface UIViewControllerHUB ()
@property (strong, nonatomic) NSMutableArray *subItems;
@end

@implementation UIViewControllerHUB

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *fullURL = @"http://conecode.com";
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_viewWeb loadRequest:requestObj];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

UIViewControllerHUB.h

#import 

@interface UIViewControllerHUB : NSObject
@property (strong, nonatomic) IBOutlet UIView *viewWeb;

@end

How can I fix this?


EVERYTHING ABOVE IS NOW RESOLVED.

New error below:

Now getting 'No visible @interface for 'UIView' declares the selector 'loadRequest:' on line

    [_viewWeb loadRequest:requestObj];

=========答:

In your code 'No visible @interface for UIView declares the selector 'loadRequest:' on line why you are getting this error is becuase loadRequest is not the method of UIView. But in-spite of that it is the method of UIWebView. For more refer this UIWebView documentation . So just replace UIViewto UIWebView and check

//Comment this

//@property (strong, nonatomic) IBOutlet UIView *viewWeb;

//Modify this

@property (strong, nonatomic) IBOutlet UIWebView *viewWeb;

Note:- As you have created outlet of UIView. So delete the same and drag-drop UIWebView and then reconnect the outlet to UIWebView

================

总结:有很多原因导致这一情况发生,但是一般而言,发生异常的代码行,指没有在interface接口文件中,找到任何你引用的selector(方法)。有可能是没有在interface进行声明定义,也有可能是字母输入错误。就是说@selector里面的方法找不到,或者引用了没有定义的方法,或者没有把定义该方法的类的.h文件import进来,或者拼错方法名了,等等。

你可能感兴趣的:(iOS开发之报错no visible @interface for XXX declares the selector YYY)