Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to call ReleaseDesignerOutlets when ViewDidUnload does not exist

When should you call ReleaseDesignerOutlets for a custom storyboard UI class when it's not a UIViewController and therefore doesn't have a ViewDidUnload method?

Fx. I have a custom UITableViewCell class, and want to release my outlets. I can see there is a protected void Dispose(bool disposing) method, but can't figure out if overriding this method is the correct way of doing it.

like image 579
RasmusWL Avatar asked May 21 '12 13:05

RasmusWL


1 Answers

In absence of ViewDidUnload I'm releasing my outlets when my view controller is removed from the navigation stack. Which will only work when using a NavigationController or with PresentViewController. Parent will be null in that case.

public override void DidMoveToParentViewController(UIViewController parent)
{
  base.DidMoveToParentViewController(parent);

  if(parent == null && cleanupOnNavigationStackRemoval)
    Cleanup();
}


protected void Cleanup()
{
  CleanupBindings();

  ReleaseOutlets();
}
like image 187
Oliver Weichhold Avatar answered Oct 19 '22 20:10

Oliver Weichhold