ios 没有可见的@interface 声明选择器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17543985/
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-08-31 00:17:21  来源:igfitidea点击:

No visible @interface declares the selector error

iphoneiosobjective-cipad

提问by Sezgin

I have a connection class in my project. I want to use this class in for a lot of works. When I tried to call this class's function getting following error : No visible @interface declares the selector error

我的项目中有一个连接类。我想在很多作品中使用这个类。当我尝试调用这个类的函数时出现以下错误:没有可见的@interface 声明了选择器错误

coreConnection.h

核心连接.h

@interface coreConnection:NSArray
{
    NSData *returnData;
}
      -(NSArray*)getData;
@end

coreConnection.m

coreConnection.m

#import "coreConnection.h"

@implementation coreConnection

-(NSArray*)getData:(NSString*)link
{
    NSOperationQueue *apiCallsQueue = [[NSOperationQueue alloc] init];
    NSURL *URL = [NSURL URLWithString:link];
    NSURLRequest *request = [NSURLRequest requestWithURL:URL];
    [NSURLConnection sendAsynchronousRequest:request queue:apiCallsQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            returnData = data;
        });
    }];
    return [NSJSONSerialization JSONObjectWithData:returnData options:nil error:nil];
}
@end

viewController.m

视图控制器.m

#import "coreConnection.h"

- (void)viewDidLoad
{
    [[self headlineCollectionView]setDelegate:self];
    [[self headlineCollectionView]setDataSource:self];
     [self.headlineCollectionView registerNib:[UINib nibWithNibName:@"HeadLineCell" bundle:nil] forCellWithReuseIdentifier:@"CELL"];
    coreConnection speed=[[coreConnection alloc] init];;
    headline = [speed getData:@"string"];
    [self.headlineCollectionView reloadData];
[super viewDidLoad];
}

采纳答案by Lithu T.V

Hehe the problem is pretty simple your method in implementation and used in code is

呵呵,问题很简单,你的实现方法和代码中使用的是

-(NSArray*)getData:(NSString*)link

not

不是

-(NSArray*)getData;

which is declared in .h file so make the declaration as

这是在 .h 文件中声明的,因此声明为

-(NSArray*)getData:(NSString*)link;

in .h file

在 .h 文件中

EDIT

编辑

You also missed *in allocing the object

你也错过 *了分配对象

Use

coreConnection *speed=[[coreConnection alloc] init];;

回答by Maulik

You just need to declare your method -(NSArray*)getData:(NSString*)link;in coreConnection.hfile.

你只需要-(NSArray*)getData:(NSString*)link;coreConnection.h文件中声明你的方法。