I have a simple app which is a combination of UITableViewController
s, UIViewController
s and UISplitViewController
s. I am bringing the Landscape orientation to my iPad app now.
I have it configured so that the in Portrait, the Master View
is hidden behind a UIBarButtonItem
and in Landscape, the Master and Detail view are both showing. I have built custom themes within my app which changes the background and the UINavigationBar
to match the selected theme.
Issue
When in Landscape and in the theme selection page, the Master view is the Menu (UITableViewController
) and the Detail is the Theme selection page (UICollectionView
). If I select a theme, the UICollectionView
updates it's background immediately to represent the new theme. However, the Master view does not update it's theme. This is the issue.
In portrait mode, the Master is updated because in it's viewWillAppear
, I have a call to the changeAppThemes
method:
- (void)changeAppThemes
{
NSLog(@"This is getting called");
self.selectedTheme = [[NSUserDefaults standardUserDefaults] objectForKey:@"Theme"];
if ([self.selectedTheme isEqualToString:@"Mystical"])
{
ThemeManager *themeManager = [ThemeManager sharedManager];
themeManager.backgrounds = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PurplepinkIPAD.png"]];
self.tableView.backgroundView = themeManager.backgrounds;
UIImage *navBackgroundImage = [UIImage imageNamed:@"Purplepinknav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
}
Within my didSelectMethod
of the UICollectionView
, I have placed a call to the changeAppThemes
method:
[[NSUserDefaults standardUserDefaults] setObject:self.selectedTheme forKey:@"Theme"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self changeAppThemes];
MasterTableViewController *master = [[MasterTableViewController alloc] init];
[master changeAppThemes];
That is working in Landscape mode because the NSLog
"This is getting called
" is displayed. However, the themes are not changing.
If I change to Portrait Mode and back to Landscape, the theme is then updated.
It seems like it's missing one key element to be updated, even though I'm explicitly calling the changeAppThemes
method from the UICollectionView
.
Any guidance on this would be really appreciated.
I think you can get the MasterTableViewController in detailView through this way if you create a UISplitViewController project with default setting through xcode.
NSArray *viewControllers = self.splitViewController.viewControllers;
UINavigationController *controller = viewControllers[0];
MasterViewController * masterController = (MasterViewController *)controller.topViewController;
[masterController changeAppThemes];
Please make sure you get the masterController in your splitViewController's viewcontrollers instead of creating a new one, the new one is not inside splitViewController.