我想在 View Controller 的自定义类中使用自定义方法
//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吗?我收到“找不到接口(interface)声明”错误
最佳答案
您的类和类别乍一看似乎是正确的,但您的 Controller 需要导入 Class1+Category.h。也许这就是你错过的?
关于ios - 自定义类 "Cannot find interface declaration"中无法识别 Objective-C 类别方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15934908/