Closed alekseybahtin closed 6 years ago
Not sure I understand the question. Can you upload her a sample?
I added example here https://github.com/abakhtin/pbrevealtest I manually load view controller as main. If I use storyboard segues it works well. Can you help please? Am I misunderstood something about main view controller set method? And the second question what is the difference between push and set segue?
All is in the title: "mainViewController is not aded to parentViewController at first call":
It is the case. You must either use the storyboard with "pb_left" and "pb_main" Set Segues or use the init method programmatically:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *leftController = [sb instantiateViewControllerWithIdentifier:@"LeftViewController"];
UIViewController *mainController = [sb instantiateViewControllerWithIdentifier:@"MainViewController"];
PBRevealViewController *revealController = [[PBRevealViewController alloc]initWithLeftViewController:leftController mainViewController:mainController rightViewController:nil];
self.window.rootViewController = revealController;
In a storyboard, the PBRevealViewControllerSegueSetController segue is for setting a controller (the equivalent of the root view controller segue for a navigation controller for example). The PBRevealViewControllerSeguePushController segue is for pushing a controller (the equivalent of the Show segue for a navigation controller).
Clear. The problem is that I want to load reveal from storyboard but set up main in code based on the flow. Why you need this crazy workaround with checking for existing controller: if (_mainViewController && animated) { [self _swapFromViewController:_mainViewController toViewController:mainViewController operation:PBRevealControllerOperationReplaceMainController animated:animated]; } Can it be improved? Or should I create revealVC in code? :)
What is the reason you want to do that?
I have different controllers that can be used as main at application start based on the business logic. But left controller is always the same and I want them to be together in single storyboard. That it is a very rare case, but I think you can add assert about it so developers can understand why it is not working.
Ok try with this version. I will update the Swift version too and push a commit but not today...
great thanks i ll check when it will be available in the repo.
When working with pure programmatically UI: Still having issue with this. All flow just breaks if setMainViewController function is called before PBReaviewViewController.loadView() method.
You have to create PBRevealViewController object first.
I call [self.revealViewController setMainViewController:viewController animated:YES]; at the application start as it is belong on the business logic which controller should be root. But as I see method for adding childViewController: [self addChildViewController:toViewController];
is called only if mainViewController exists: if (_mainViewController && animated) { [self _swapFromViewController:_mainViewController toViewController:mainViewController operation:PBRevealControllerOperationReplaceMainController animated:animated]; }
It brakes my responder chain for actions handling in revealviewcontroller.