美文网首页iOS开发攻城狮的集散地
iOS开发小点·移除所有子视图

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

作者: 小码僧 | 来源:发表于2018-10-18 10:54 被阅读108次

需求: 移除所有子视图

  • 思路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];
}];

相关文章

网友评论

    本文标题:iOS开发小点·移除所有子视图

    本文链接:https://www.haomeiwen.com/subject/oxejzftx.html