Remove all subviews?

前端 未结 15 1709

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?

15条回答
  •  眼角桃花
    2020-11-28 00:52

    Using Swift UIView extension:

    extension UIView {
        func removeAllSubviews() {
            for subview in subviews {
                subview.removeFromSuperview()
            }
        }
    }
    

提交回复
热议问题