iOS开发小点·移除所有子视图

需求: 移除所有子视图

  • 思路1 - OC的API
[view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  • 思路2 - 循环
for(UIView *view in [self.view subviews]){
   [view removefromsuperview]
}
  • 思路3 - 枚举
[[self.view subviews] enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
   [(UIView*)obj removeFromSuperview];
}];

推荐阅读更多精彩内容