objective-c – “没有可见的@interface为’BlahDataController’声明选择器’aMethod:’”

一个简单的例子我的问题:

“在BlahDataController.h”

@interface BlahDataController : NSObject
-(Nsstring *)aMethod:(Nsstring *)theString;
@end

“在BlahDataController.m”

#import "BlahDataController.h"
@implementation BlahDataController

-(Nsstring *)aMethod:(Nsstring *)theString
{
    return @"Something";
}

@end

“在BobViewController.h”

@interface BobViewController : NSObject
-(void)aMethodofSomeSort;
@end

“在BobViewController.m”

#import "BobViewController.h"
#import "BlahDataController.h"

@implementation BobViewController

-(void)aMethodofSomeSort
{
    BlahDataController *blahDataController = [[BlahDataController alloc] init];
    NSLog(@"%@",[blahDataController aMethod:@"Variable"]);
}

@end

在行“NSLog(@”%@“,[blahDataController aMethod:@”Variable“]);”我收到错误:“没有可见的@interface为’BlahDataController’声明选择器’aMethod:’”

任何人知道为什么这个错误发生?

– = – = – = – = – = – = – = – = – = – =

事情是,在我的实际程序,我有这个相同的实现,它适用于数百这种方式创建的方法。然而,经常,我会收到这个错误一个新创建的方法。我没有做出任何不同的。它只是不会认出它的新创造的存在。

– = – = – = – = – = – = – = – = – = – =

这是我目前绕开它,虽然我不知道为什么编译器接受这种方式,但不是其他:

修改BobViewController.m:

#import "BobViewController.h"
#import "BlahDataController.h"
#import "AnotherDataController.h"

@implementation BobViewController

-(void)aMethodofSomeSort
{
    BlahDataController *blahDataController = [[BlahDataController alloc] init];
    AnotherDataController *anotherDataController = [[AnotherDataController alloc] init];
    [anotherDataController fixedMethod:blahDataController theString:@"Variable"];
}

@end

“在AnotherDataController.h”

@interface AnotherDataController : NSObject
-(void)fixedMethod:(BlahDataController *)blahDataController theString:(Nsstring *)theString;
@end

“在AnotherDataController.m”

#import "AnotherDataController.h"
#import "BlahDataController.h"
@implementation AnotherDataController

-(void)fixedMethod:(BlahDataController *)blahDataController theString:(Nsstring *)theString
{
    NSLog(@"%@",[blahDataController aMethod:theString]);
}
@end

所以我想象xcode只是不能识别一个类中的方法,并在另一个工作作为它应该在…人,我不知道为什么这个错误发生.. 。

– = – = –

次要更新:
做整个“xcode舞蹈”没有解决这个问题
1)清洁生产
2)删除派生数据
3)完全关闭XCode并重新打开

解决方法

好的,对于所有那些在未来的这个问题;这是什么问题。

几个月前我做了BlahDataController。大约一个星期前,我重新构建了项目的文件夹,并将BlahDataController从名为“Blah”的文件夹移动到另一个名为“Data”的文件夹。

当我改变了“数据”文件夹中的BlahDataController的代码,我的一个类可以看到更改的代码,但是,另一个类不能。

最终出现的问题是,当我移动BlahDataController,它实际上创建了一个副本。所以我在“数据”文件夹中有一个BlahDataController,在“Blah”文件夹中有一个旧的BlahDataController。即使较旧的BlahDataController不再连接到项目管理器中的项目(xcode的左侧),物理文件仍然存在于文件夹中的事实导致此问题。

删除BlahDataController的重复旧副本后,问题已解决

tl; dr – 在项目的某个地方有一个重复的文件!去追捕它,无情地摧毁它!

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...