在Objective-C中,我使用以下代码删除所有子视图:
[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
但是如何迅速使用它呢?我看到苹果文档迅速使用了该方法
func makeObjectsPerformSelector(_ aSelector: Selector)
但是当我尝试它时,出现错误: 'AnyObject[]' does not have a member named 'makeObjectsPerformSelector'
'AnyObject[]' does not have a member named 'makeObjectsPerformSelector'
有什么方法可以快速删除子视图?
用途forEach:
forEach
self.view.subviews.forEach { subview in subview.removeFromSuperview() }
或像这样:
view.subviews.forEach { $0.removeFromSuperview() }