Search code examples
objective-cstoryboardjasidepanels

Use .xib/storyboard file as interface source of JASidePanels


I'm trying to implement in my project a JASidePanels, but first I was trying to create an interface such a .xib file or storyboard where I can drag items instead the programmatically created default interface in the project.

I'm follwing steps of Example 2: Storyboards section.

But this is exactly what I'm doing based on the example, I'm new in iOS.

First in JASidePanels/Source I add a New File "Cocoa Touch Class" and name it "MySidePanelController" with sublass of JASidePanelController.

Then I add a storyboard file in the same folder and add 3 View Controllers inside, in each I give identifiers.

Finally I add the method -(void) awakeFromNib to MySidePanelController.m

Run the app and the JASidePanels app shows the same initial content as when I dowloaded it.

Do I missing something? I'm pretty sure

How can I load the interface from a xib file or storyboard?


Solution

  • Ok, it was simple, step 4 is the key

    1. Create a new project
    2. Add this two files JASidePanelController.h & JASidePanelController.m to your project.
    3. Add a New File "Cocoa Touch Class" and name it "MySidePanelController" (for example) with subclass of JASidePanelController.
    4. In the Main.storyboard click Show the identity inspector in Custom Class section set in Class field: MySidePanelController
    5. Add more view controllers to your Storyboard, and give them identifiers "leftViewController", "centerViewController" and "rightViewController". Note that in the new XCode the identifier is called "Storyboard ID" and can be found in the Identity inspector (in older versions the identifier is found in the Attributes inspector).

    6. Add a method awakeFromNib to MySidePanelController.m with the following code:

    -(void) awakeFromNib
    {
        [self setLeftPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"leftViewController"]];
        [self setCenterPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"centerViewController"]];
        [self setRightPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"rightViewController"]];
    }