I'm looking for a simple method to remove at once all subviews from a superview instead of removing them one by one.
//I'm trying something like this, but is not working
let theSubviews : Array = container_view.subviews
for (view : NSView) in theSubviews {
view.removeFromSuperview(container_view)
}
What I am missing?
UPDATE
My app has a main container_view
. I have to add different other views as subviews to container_view
in order to provide a sort of navigation.
So, when clicking the button to "open" a particular page, I need to remove allsubviews and add the new one.
UPDATE 2 - A working solution (OS X)
I guess Apple fixed it.
Now it is more easy than ever, just call:
for view in containerView.subviews{
view.removeFromSuperview()
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…