jondanao / TheSidebarController

A container view controller that implements different popular sidebar view controllers like Facebook, Airbnb, Flipboard, etc.
Other
360 stars 52 forks source link

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

Open vu0tran opened 10 years ago

vu0tran commented 10 years ago

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...

jonahgabriel commented 10 years ago

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;