开发者

some custom UIView lost after my iPad app received memory warning

开发者 https://www.devze.com 2023-02-01 07:51 出处:网络
I\'m developing an app to browse online photos, and sometimes received memory warning(level 1), after that, if I go b开发者_如何学编程ack to last UIViewController(in a NavigationControll), I found tha

I'm developing an app to browse online photos, and sometimes received memory warning(level 1), after that, if I go b开发者_如何学编程ack to last UIViewController(in a NavigationControll), I found that some custom UIView lost, I cannot get them back, but I can create new such UIView

does anyone know the problem?


The memory warning prompts the os to dump any unneeded views. If you create them in IB, or in the viewDidLoad or loadView method in your view controller they'll be re-created when your view re-loads. You could also have your view controller retain them specifically, but that'll have a larger memory footprint than just re-creating them whenever they're needed.

I should say, loadView is only called if you don't use a nib for creating your view, so viewDidLoad is probably where you want to put them.


It's expected behavior. You can override didReceiveMemoryWarning (i.e. do nothing and don't call on super); but what you really want is to handle those situations correctly, i.e. set the views up again if necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消