Search code examples
iphonexcodeuiviewcontrolleruistoryboardiboutletcollection

hooking up two different storyboard viewcontrollers to a same class


I am new to Iphone development. My app consists of two storyboards one for the Ipad and other for the Iphone.Now, my problem is I have an IBOutletCollection of UILabels hooked up as a property with one of the viewcontrollers in my Iphone storyboard..How am I suppose to hook up the same Ipad storyboard viewcontroller with the IBOutletCollection of UILabels for the same class..? Thanks in advance..


Solution

  • Just like you'd hook up any other IBOutlet, IBOutletCollection or IBAction.

    Your UIViewController sub-class contains the bits which let you hook something in a storyboard to it.

    @property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *tabButtons;
    

    In your storyboard, you can assign the view controller to be of a certain class, in this case it will be a your UIViewController sub-class. Now all you have to do it drag the storyboard artifacts to your existing IBOutlet stubs. It works.

    You can do this for multiple storyboards using the same class (or multiple view controller in the same storyboard too). When you load it into memory, you specify the item in the storyboard, then the storyboard creates and instance of the view controller and hooks up all the references, so all is good.

    MyViewController *myVC = [storyboard instantiateViewControllerWithIdentifier:@"foo"];