2
我想使用一个自定义类的定制方法,在我的ViewController目标C类方法“找不到接口声明”
//Viewcontroller.h
#import "Class1.h"
//Class1.h
//#import "Class1+Category.h" // Deemed unnecessary in comments below.
@interface Class1: NSObject
-(void)doSomething;
@end
//Class1.m
#import "Class1.h"
@implementation Class1
-(void)doSomething{
NSLog("In doSomething");
}
@end
现在我想的Class1的类中的方法。
//Class1+Category1.h
#import "Class1.h"
@interface Class1 (Category1) // ERROR : Cannot find interface declaration
-(void)doAnotherThing;
@end
//Class1+Category1.m
#import "Class1+Category.h"
@implementation Class1 (Category1)
-(void)doAnotherThing{
NSLog(@"Did Another thing");
}
@end
最后 - 在我viewcontroller.m我看到doSomething的方法,但不是doAnother事情
//viewcontroller.m
Class1 *myClass1 = [[Class1 alloc]init];
[Class1 doSomething]; //Works great!
[Class1 doAnotherThing]; //Not recognized
我已经加入了-all_load到我的目标设定。我没有想法..我使用@class吗?我得到'无法找到接口声明'错误
你确定#import“Class1 + Category.m”不应该是#import“Class1 + Category.h”吗? viewcontroller.m也应该导入类别.h – 2013-04-10 19:41:34
不,我只是编辑了..我正在使用虚拟值..我的错误。 – mattyd 2013-04-10 19:42:42
为什么Class1.h导入Class1 + Category.h?这没有理由。 – rmaddy 2013-04-10 19:43:45