問題:
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
.我的應用程序有一個主container_view
。 I have to add different other views as subviews to container_view
in order to provide a sort of navigation.我必須將不同的其他視圖作爲子視圖添加到container_view
以提供一種導航。
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)更新 2 - 一個有效的解決方案 (OS X)
I guess Apple fixed it.我猜蘋果修復了它。
Now it is more easy than ever, just call:現在比以往任何時候都更容易,只需調用:
for view in containerView.subviews{
view.removeFromSuperview()
}
解決方案:
參考一: https://en.stackoom.com/question/1e0rI參考二: https://stackoom.com/question/1e0rI