Question

I'm quite new to IOS so I'm sorry if my question is obvious. I have set a ViewController's view in storyboard which contains other subviews.

In viewWillAppear I update these subviews depending on the object I passed to this ViewController. This object can have nil attributes and in this case I want to remove these subviews.

What is the right place to remove these subviews and is there a difference in terms of efficiency?

  • viewDidLoad
  • viewWillAppear
  • or viewWillLayoutSubviews ?

and will the constraints set to these removed objects also be removed?

Thx

Was it helpful?

Solution

The constraints will definitely be removed. However, it is possible to save the constraints in an array and add them back again in the future.

I would suggest making changes to the views( orientation, visibility, geometry ) in the viewWillLayoutSubviews method. You wouldn't want to do anything expensive in the ViewWillAppear method, because at that point the view is ready to be displayed to the user and it could impact how quickly the view appears to load for the user.

OTHER TIPS

If you are using Storyboard and ARC do not worry about removing your views, conversely, if you are very interested to keep your memory under very tight control then do not use Storyboard and remove ARC.

What you refer to subviews are not subviews, the methods you listed are not UIView methods, and instead are UIViewController methods. However, if you have UIView objects that you are trying to remove, then those will also be handled for you. If you want more tight control, then declare them as public ivars, wrap them in @autoreleasepool {}, and set to nil in viewWillDisappear: or other method, or via delegate or notification pattern. It's relative to what you are doing and your conditions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top