Remove all subviews?

前端 未结 15 1727

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 01:05

    If you're using Swift, it's as simple as:

    subviews.map { $0.removeFromSuperview }
    

    It's similar in philosophy to the makeObjectsPerformSelector approach, however with a little more type safety.

提交回复
热议问题