Reputation: 1882
I subclassed UIViewController
(let's call it ParentViewController
) and added a bunch of properties and methods -- IBOutlets and IBActions and such -- that I want to subclass for ChildViewControllerA
, ChildViewControllerB
, ChildViewControllerC
, etc.
My stupid question is, since all of these properties are defined in ParentViewController's
interface, how do I hook them up in the ChildViewControllers
' interfaces? In my ios 7 storyboard main file, I have a ViewController for each one of ChildViewControllerA
, ChildViewControllerB
, ChildViewControllerC, etc. but I don't have the little plus-sign ports in their corresponding .h/.m files because they are all in ParentViewController.h
.
Is there something I'm missing? Do I need to redefine the properties in each ChildViewController
in order to have some place to hook them up to their corresponding storyboard views?
Upvotes: 0
Views: 872
Reputation: 12719
The logic is quite simple, if you inherit any class the Outlets will be available to all the other classes which inherits it. For eg.
In your case you have Parent
and in it you have Outlet say a ButtonA
. Now other classes Child1
and Child2
inherits Parent
they can access ButtonsA
, but if you create any outlet to Child1
and Child2
and if no other class inherits it, it wont be available for any, and it wont be available for Parent
as well.. If you want to access the properties you can have the Child Controller
as a property in any one of your class.
Hope this helps.
Upvotes: 0
Reputation: 9185
This should work in the manner your described; as I just verified.
@interface ParentViewController : UIViewController
@property (nonatomic, weak) IBOutlet UILabel *someLabel;
@end
Create subclasses of ParentViewController
and set the custom classes in the Storyboard editor to ChildViewControllerA
and ChildViewControllerB
, like so:
The outlets should be there if this corresponds to what you're doing.
In short, you should not need to redefine outlets that are defined earlier in the object hierarchy.
Upvotes: 2
Reputation: 1578
What do you try to do? If you try to pass parameters to another view controller, use this method in your ParentViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[segue.destinationViewController yourInitializationMethod:withProperties];
}
Upvotes: 0