I have a superclass of UIViewController – MasterViewController which declares a property called itemsViewController. This declares a method called from the MasterViewController, and is wired up via a storyboard in IB.
I have a subclass of MasterViewController which redeclares this property as a specific iPad version, but I can’t access the redeclared property from the parent class.
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
Am I misunderstanding the way property inheritance works in Objective-C?
You can’t change the type signature of a method when you override a superclass method.
MasterViewControllerhas these methods:But you’re trying to give
MasterViewController_iPadthese methods:Which you can’t do: you can’t overload the same method name but have different types for the arguments.
If
ItemsViewController_iPadis a subclass ofItemsViewController, a quick solution would be to keep the same signature as inMasterViewControllerbut simply use anItemsViewController_iPadwhen you set the property.