TheSidebarController icon indicating copy to clipboard operation
TheSidebarController copied to clipboard

When trying to instantiate from a storyboard, the sidebar screens become unresponsive?

Open vu0tran opened this issue 11 years ago • 1 comments

Here's the code I'm using below. When I instantiate a UIViewController from a storyboard rather than a xib, none of the UIButtons are responsive. It's as if they were behind an invisible layer. (I've made sure to enable user interactions)

When I instantiate with alloc init and add UIButtons programatically on the UIViewController's ViewDidLoad method however, it works.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Get the main storyboard    
    UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

    PSMainViewController *centerViewController = [main instantiateViewControllerWithIdentifier:@"PSMainViewController"];
    UINavigationController *contentViewController = [[UINavigationController alloc] initWithRootViewController:centerViewController];

    PSLeftSidebarViewController *leftViewController = [main instantiateViewControllerWithIdentifier:@"PSLeftSidebarViewController"];

    PSRightSidebarViewController *rightViewController = [main instantiateViewControllerWithIdentifier:@"PSRightSidebarViewController"];

    PSRootViewController *sidebarController = [[PSRootViewController alloc] initWithContentViewController:contentViewController leftSidebarViewController:leftViewController rightSidebarViewController:rightViewController];
    sidebarController.delegate = self;

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = sidebarController;
    [self.window makeKeyAndVisible];
}

It seems to be working when I use [[UIViewController alloc]init] and adding UIViews on the main ViewDidLoad though...

vu0tran avatar Feb 05 '14 23:02 vu0tran

It looks like the problem is due to Autolayout. I disabled Autolayout in my storyboard and things work fine. If you want to use Autolayout, open up TheSidebarController.m and set translatesAutoresizingMaskIntoConstraints to YES for the side bar controllers you wish to use Autolayout with.

Example:

self.leftSidebarContainerViewController.view.translatesAutoresizingMaskIntoConstraints = YES;

jonahgabriel avatar Mar 20 '14 18:03 jonahgabriel