When my app gets back to its root view controller, in the viewDidAppear:
method I need to remove all subviews.
How can I do this?
When my app gets back to its root view controller, in the viewDidAppear:
method I need to remove all subviews.
How can I do this?
Get all the subviews from your root controller and send each a removeFromSuperview:
Try this way swift 2.0
For ios6 using autolayout I had to add a little bit of code to remove the constraints too.
I'm sure theres a neater way to do this, but it worked for me. In my case I could not use a direct
[tagview removeConstraints:tagview.constraints]
as there were constraints set in XCode that were getting cleared.In Swift you can use a functional approach like this:
As a comparison, the imperative approach would look like this:
These code snippets only work in iOS / tvOS though, things are a little different on macOS.
Using Swift
UIView
extension: