“在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只是不能识别一个类中的方法,并在另一个工作作为它应该在…人,我不知道为什么这个错误发生.. 。
– = – = –
解决方法
几个月前我做了BlahDataController。大约一个星期前,我重新构建了项目的文件夹,并将BlahDataController从名为“Blah”的文件夹移动到另一个名为“Data”的文件夹。
当我改变了“数据”文件夹中的BlahDataController的代码,我的一个类可以看到更改的代码,但是,另一个类不能。
最终出现的问题是,当我移动BlahDataController,它实际上创建了一个副本。所以我在“数据”文件夹中有一个BlahDataController,在“Blah”文件夹中有一个旧的BlahDataController。即使较旧的BlahDataController不再连接到项目管理器中的项目(xcode的左侧),物理文件仍然存在于文件夹中的事实导致此问题。