I have a view that needs to be presented in Landscape and Portrait view both. I used this solution to provide orientation: Solution for orientation in Storyboard
So now my view is like this:
The selected view is the View of the ViewController, that has two views: First one being the Portrait View, and Second one being the Landscape view. I hide the view which is not according to the orientation of the device.
As in the image, both the views, Portrait and Landscape have Container views, linked to view controllers through segue.
To my understanding, the Storyboard should call all the segues while loading the main view controller. And I am getting the Segue call at prepareForSegue
method.
If the Portrait view is kept before the landscape view, prepareForSegue
is called first for segues from "Portrait view", where I save the destination viewController in an object. and then for the segues for "Landscape View". But when the Landscape view segues are called, the destination viewController for Portrait Segues become nil
(which were saved in a global object).
Why does this happen, and How can I resolve this so that all the container views are loaded properly.
EDIT
prepare for segue method: - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSString * segueName = segue.identifier;
if ([segueName isEqualToString: @"ChartEmbedSegue"])
{
self.chartViewController = (ChartViewController *) [segue destinationViewController];
self.chartViewController.dataSource = [[ServiceManager sharedInstance] dataSource];
self.chartViewController.view.frame = self.chartContainerView.bounds;
}
else if ([segueName isEqualToString: @"LandscapeChartEmbedSegue"])
{
self.landscapeChartViewController = (ChartViewController *) [segue destinationViewController];
self.landscapeChartViewController.dataSource = [[ServiceManager sharedInstance] dataSource];
self.landscapeChartViewController.view.frame = self.chartContainerView.bounds;
}
else if ([segueName isEqualToString: @"SummaryControllerEmbedSegue"])
{
self.summaryViewController = (SummaryViewController *) [segue destinationViewController];
self.summaryViewController.data = self.data;
self.summaryViewController.view.frame = self.summaryView.bounds;
}
else if ([segueName isEqualToString: @"LandscapeSummaryControllerEmbedSegue"])
{
self.landscapeSummaryViewController = (SummaryViewController *) [segue destinationViewController];
self.landscapeSummaryViewController.data = self.data;
self.landscapeSummaryViewController.view.frame = self.landscapeSummaryView.bounds;
}
}