Reputation: 3
I'm working through Paul Hegarty's course on iTunesU on developing iOS7 Apps. In assignment 3, I was required to make my view controller abstract and then make two concrete subclasses of it. The outlets in the original view controller were declared in the .m
file as follows:
@interface CardGameViewController ()
@property (weak, nonatomic) IBOutlet UIlabel *scorelabel;
@end
My problem is that my subclasses of CardGameViewController
do not know about these properties since, I presume, they are private.
In his hints for the assignment, Paul suggested an idea to get around this without making these outlet property declarations public:
"If you subclass a subclass of UIViewController, you can wire up to the superclass’s outlets and actions simply by manually opening up the superclass’s code in the Assistant Editor in Xcode (side-by-side with the storyboard) and ctrl-dragging to it as you normally would. In other words, you are not required to make a superclass’s outlets and actions public (by putting them in its header file) just to wire up to them with ctrl-drag (it is quite possible to implement this entire assignment without making a single outlet or action public)."
My question is: does this mean any code which uses these outlet properties must exist in the superclass implementation? Or is there a way for my subclass to access these properties?
Upvotes: 0
Views: 861
Reputation: 23
Yes,you are right. He said: you are not required to make a superclass’s outlets and actions public (by putting them in its header file) just to wire up to them with ctrl-drag.
It means you don't need to make a superclass’s outlets and actions public, but it should be in the implementation file.
And in his tutorial, the scoreLabel property has already been in the CardGameViewController implementation file.
Upvotes: 0
Reputation: 38728
If you wanted to use the outlets in a subclass you would need to make them visible to the subclass in some way.
You can do this by making them publicly visible - place them in the header
or
You can make a new header that is to be imported by subclasses only (this is how UIGestureRecognizer
subclasses work)
@interface MyClass (ForSubclassEyesOnly)
@property (nonatomic, strong) id propertyThatYouWantToMakeVisibleToSubclass;
@end
Upvotes: 1