iOS: viewDidLoad deprecated in iOS 6

So with viewDidUnload deprecated as of iOS 6, what do I need to do now?


Generally, most of us do the setting of IBOutlet references to nil in viewDidUnload (largely because Interface Builder would put that there for us) and do the general freeing of memory (e.g. clearing of caches, releasing of easily recreated model data, etc.) in didReceiveMemoryWarning. If that's the way you do it, then you probably don't require any code changes.
According to the iOS 6 viewDidUnload documentation:
Views are no longer purged under low-memory conditions and so this method is never called.
Therefore, you do not want to move the setting of your IBOutlet references to nil anywhere, because the views are no longer purged. It would make no sense to set them to nil indidReceiveMemoryWarning or anything like that.
But, if you were responding to low memory events by releasing easily-recreated model objects, emptying caches, etc., in viewDidUnload, then that stuff should definitely move todidReceiveMemoryWarning. But then, again, most of us already had it there already.
Finally, if you free anything in didReceiveMemoryWarning, just make sure your code doesn't rely upon them being recreated in viewDidLoad again when you pop back, because that will not be called (since the view, itself, was never unloaded).




page32image12072 page32image12768
- (void)viewDidUnload 
{
  [super viewDidUnload]; 

  var1 = nil;
  var2 = nil; 
}
page32image21320 page32image22016



- (void)didReceiveMemoryWarning 
{
  [super didReceiveMemoryWarning];
  if ([self isViewLoaded] && self.view.window == nil) 
  {
    self.view nil;
page32image37016
page33image1848 page33image2544
    var1 nil;
    var2 nil; 
  }
}



First this method checks whether the view is still loaded. This is necessary because accessing the self.view property will always load the view if it isn’t, and that’s something you don’t want to happen here! If the view is no longer part of the window, then you can safely unload it (and its subviews) by setting self.view to nil.

Second, this method gets rid of the cached data from the two arrays, replicating the old viewDidUnload behavior. The app should again behave the way it did on iOS 5 and earlier. 
page33image6792
iOS: viewDidLoad deprecated in iOS 6 iOS: viewDidLoad deprecated in iOS 6 Reviewed by Unknown on 15:48 Rating: 5

No hay comentarios:

Con la tecnología de Blogger.