我有一個UIViewController的超類 - MasterViewController
,它聲明瞭一個名爲itemsViewController
的屬性。這聲明瞭從MasterViewController調用的方法,並通過IB中的故事板進行了佈線。超類的重寫屬性
我有一個MasterViewController的子類,它將此屬性重新聲明爲特定的iPad版本,但我無法從父類訪問重新聲明的屬性。
MasterViewController
@interface MasterViewController : UIViewController {
}
@property (nonatomic, strong) IBOutlet ItemsViewController *itemsViewController;
@end
@implementation MasterViewController
@synthesize itemsViewController;
-(void)viewDidLoad {
// I can access itemsViewController in viewDidLoad.
}
@end
MasterViewController_iPad
@interface MasterViewController_iPad : MasterViewController {
IBOutlet ItemsViewController_iPad *_itemsViewController;
}
@property (nonatomic, strong) IBOutlet ItemsViewController_iPad *itemsViewController;
@end
@implementation MasterViewController_iPad
@synthesize itemsViewController = _itemsViewController;
-(void)viewDidLoad {
[super viewDidLoad];
// when I call super viewDidLoad, itemsViewController is nil, as though the property hasn't been overriden
// _itemsViewController is not nil in viewDidLoad.
}
@end
我誤解的方式財產繼承在Objective-C的作品?
不理想,但它我會相信的。 – Echilon 2012-03-07 14:28:33