Search code examples
iosobjective-copen-sourcestoryboard

JASidePanels example-2 using storyboards : crash


I am trying to implement the JASidePanels example2 using storyboard. https://github.com/gotosleep/JASidePanels#example-2-storyboards

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

If I added above code into CenterViewController.m that was as same as MySidePanelController.m in the example2, the app was crashed like below.

https://dl.dropboxusercontent.com/u/6655378/stack1.png

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

If I commented out like above, the app worked like below. ttps://dl.dropboxusercontent.com/u/6655378/stack2.png

I'm new to iOS. Could you tell me what is wrong?

My environment.

  • XCode : Version 4.6.2
  • iOS SDK : 6.1
  • Simulator : iPhone 6.1

Solution

  • You are causing a stackoverflow by calling the code in -awakeFromNib in your center view controller as it sets another center view controller as its center panel and goes this way till the app crashes.

    You need to have a subclass of JASidePanelController where you implement the-awakeFromNib and your other 3 view controllers that you set as panels.

    #import "JASidePanelController.h"
    
    @interface MyPanelsController : JASidePanelController
    
    @end
    
    
    #import "MyPanelsController.h"
    
    @implementation MyPanelsController
    
    -(void)awakeFromNib
    {
        [self setLeftPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"leftViewController"]];
        [self setCenterPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"centerViewController"]];
        [self setRightPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"rightViewController"]];
    }
    
    @end
    

    And in your storyboard drag a UIViewController and set its class to MyPanelsController and set it as the initial view controller.