some custom UIView lost after my iPad app received memory warning
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.
精彩评论