[英]Changing the background image of a UITableViewController Master of a UISplitViewController in Landscape orientation
I have a simple app which is a combination of UITableViewController
s, UIViewController
s and UISplitViewController
s. 我有一个简单的应用程序,它是
UITableViewController
, UIViewController
和UISplitViewController
的组合。 I am bringing the Landscape orientation to my iPad app now. 我现在将“横向”应用到我的iPad应用程序中。
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. 我对其进行了配置,以使“纵向”中的“
Master View
隐藏在UIBarButtonItem
后面,而在“横向”中,“主视图”和“详细视图”都显示出来。 I have built custom themes within my app which changes the background and the UINavigationBar
to match the selected theme. 我在应用程序中构建了自定义主题,该主题
UINavigationBar
背景和UINavigationBar
以匹配所选主题。
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
). 在横向模式和主题选择页面中时,主视图是Menu(
UITableViewController
),Detail是主题选择页面( UICollectionView
)。 If I select a theme, the UICollectionView
updates it's background immediately to represent the new theme. 如果选择主题,则
UICollectionView
会立即更新其背景以表示新主题。 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: 在纵向模式下,母版已更新,因为在它的
viewWillAppear
,我调用了changeAppThemes
方法:
- (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: 在
UICollectionView
didSelectMethod
中,我对changeAppThemes
方法进行了调用:
[[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. 这在横向模式下有效,因为显示了
NSLog
“ This is getting called
”。 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
. 即使我从
UICollectionView
显式调用changeAppThemes
方法,它似乎也缺少要更新的一个关键元素。
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. 我认为,如果通过xcode创建具有默认设置的UISplitViewController项目,则可以通过这种方式在detailView中获得MasterTableViewController。
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. 请确保在您的splitViewController的viewcontrollers中获得masterController,而不是创建一个新的masterController,新的不是在splitViewController内部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.