TheSidebarController
TheSidebarController copied to clipboard
When trying to instantiate from a storyboard, the sidebar screens become unresponsive?
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...
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;