2010-09-12 30 views
4

当我在基于导航的iPhone应用程序中收到内存警告时,背景图像在先前分配的导航控制器中消失。iPhone应用程序 - 内存警告后背景消失

背景图像被设置为UIView的背景属性。然后,该视图被添加到应用程序委托的主窗口:

UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame]; 

backgroundView.backgroundColor = [的UIColor colorWithPatternImage:[[用具sharedManager] getImageWithName:@ “Hintergrund2”]]; backgroundView.tag = 56789; [window addSubview:backgroundView]; [backgroundView release];

[window addSubview:[navigationController view]]; 

[window makeKeyAndVisible]; 

当我收到内存警告信息并按下导航控制器的后退按钮时,以前的导航控制器显示正常的Apple灰色背景。我必须回到我的主屏幕并向前导航以“重置”背景图像。

谁能告诉我为什么背景消失?这不是因为图像,当我将背景设置为像blackColor这样的标准UIColor时,背景(颜色)也消失了。

预先感谢您的帮助!

问候

菲尔

回答

2

它是不确定的是什么操作系统确实有东西在低内存情况下的情况下,直接添加到主UIWindow

也许考虑使用简单的UIViewController作为背景?当内存不足时,您至少会得到回调。

+0

感谢您的意见。我做了以下没有成功: – 2010-09-13 21:42:47

+0

navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[[Utilities sharedManager] getImageWithName:@“Hintergrund2”]]; – 2010-09-13 21:43:29

0

首先,你应该你的控制器添加到窗口是这样的:

window.rootViewController = navigationController; 

我没有测试过这一点,但也许你可以直接设置窗口的背景颜色:

window.backgroundColor = [UIColor colorWithPatternImage:[[Utilities sharedManager] getImageWithName:@"Hintergrund2"]]; 

如果不工作,你需要一个更好的方式来重新创建内存不足的情况下你的视图状态。最标准的方法是在每个xib中定义背景,然后重新加载。或者,您可以通过查看backgroundView是否具有超级视图来捕获低存储量警告并根据需要重新创建。

0

确保您在视图控制器的- (void) viewDidLoad中设置调用self.view.backgroundColor = [UIColor clearColor];,否则窗口的图像将不会显示。

- (void) viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.view.backgroundColor = [UIColor clearColor]; 
... 
} 

我的问题是,我设置视图的backgroundColor初始化时

MyTableViewController *myTVC = 
    [[MyTableViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
myTVC.view.backgroundColor = [UIColor clearColor]; 

,而不是在- (void) viewDidLoad

在这种情况下,UITableViewController的视图的背景颜色是在最初创建后设置的。但是,在低存储器警告之后,没有显示的UIViewController已经调用- (void) viewDidUnload。这释放了他们的意见。在UIViewController被再次显示之前,- (void) viewDidLoad被调用并创建了一个新的视图,但视图的背景颜色被设置为默认的不明确。