请注意,您不必释放视图以响应内存警告。iOS 6 自动释放幕后视图使用的大部分资源。
如果您选择释放视图,那么只有当它
当前在屏幕上不可见时才应该这样做:
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Add code to clean up any of your own resources that are no longer necessary.
// If view is currently loaded, but not visible:
if ([self isViewLoaded] && [self.view window] == nil)
{
// Add code to preserve data stored in the views that might be
// needed later.
// Add code to clean up other strong references to the view in
// the view hierarchy.
// Unload the view:
self.view = nil;
}
}
(来自iOS 视图控制器编程指南的代码,稍作修改以避免在当前卸载视图时加载视图。)
使用此代码,如果视图再次可见,则应自动重新加载视图。