美文网首页
removeFromSuperview移除子视图

removeFromSuperview移除子视图

作者: 番薯大佬 | 来源:发表于2018-06-04 10:29 被阅读10次

    移除子视图的使用方法
    方法1

    for (UIView *subview in self.containerView.subviews) {
            [subview removeFromSuperview];
    }
    

    方法2

    for (NSInteger i = view.subviews.count; i > 0; i--)
    {
            UIView *subView = [view.subviews objectAtIndex:(i - 1)];
            [subView removeFromSuperview];
    }
    

    方法3

    [self.containerView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [obj removeFromSuperview];
    }];
    

    方法4

    [self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    

    方法5

    [self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    

    方法6

    [self.containerView.subviews performSelector:@selector(removeAllObjects)];
    

    相关文章

      网友评论

          本文标题:removeFromSuperview移除子视图

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