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