简体   繁体   English

在横向方向上更改UISplitViewController的UITableViewController的背景图像

[英]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. 我有一个简单的应用程序,它是UITableViewControllerUIViewControllerUISplitViewController的组合。 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. 这在横向模式下有效,因为显示了NSLogThis 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.

相关问题 具有非UITableViewController的自定义主视图控制器的UISplitViewController - UISplitViewController with custom master view controller that is not UITableViewController UISplitViewController在iPad横向上隐藏主视图 - UISplitViewController hide master view on iPad landscape UISplitViewController-在iPad横向中隐藏主视图 - UISplitViewController - hiding master view in iPad landscape UINavigationController + UITableViewController 在横向方向的返回转换错误 - Back Transition Wrong in UINavigationController + UITableViewController in Landscape Orientation UISplitViewController:DetailViewController 中的 titleView 在横向上消失,预期行为? - UISplitViewController: titleView in DetailViewController disappears on landscape orientation, intended behaviour? 扩展了UITableViewController背景图像 - UITableViewController background image stretched UIWebView在切换到横向时不会改变方向 - UIWebView not changing orientation on switch to landscape 点击一个项目并将方向从纵向更改为横向后,主视图控制器消失 - Master view controller disappears after tapping an item and quickly changing orientation from portrait to landscape 更改母版的宽度后刷新UISplitViewController - Refresh UISplitViewController after changing the Master's width UITableViewController - 图像背景 - UITableViewController - image background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM