-1
作爲主題作爲主題。存在類ObjectSubA
存在的問題,我無法調用對象ObjectX
的方法。在一種情況下,方法必須具有相同的方法名稱。將方法從子對象傳遞到聲明爲NSObject的第1個(頭)對象的方法
file.h
@interface ObjectX : NSObject
- (void) insert;
@end
@interface ObjectSubA : ObjectX
- (void) insert;
@end
@interface ObjectSubB : ObjectX
@end
file.m
@implementation ObjectX
- (void) insert{
NSLog(@"answer");
}
@end
@implementation ObjectSubA
-(void)insert{
NSLog(@"nothing")
[self insert]; // <- need answer, should call insert from ObjectX
}
@end
@implementation ObjectSubB
@end
@implementation app
-(void)launch{
ObjectSubA * a = [[ObjectSubA alloc]init];
[a insert]; // ObjectSubA -> method insert -> ObjectX -> insert -> end. #ERROR
ObjectSubB * b = [[ObjectSubB alloc] init];
[b insert]; //ObjectX -> insert -> end. OK
}
@end
此外,如果在父接口中已經定義了''insert',則不需要在ObjectSubA接口中定義'insert'。只需在ObjectSubA中執行即可。 – Jaanus
當然,但我懷疑有更多的代碼涉及比日誌行 – vadian
謝謝你!這工作;)我已經忘記了'超'。 – machei