I need to remove image subviews
from a ScrollView
and I tried removing from the array
of subviews
but that is an NSArray
which is immutable.
How can a subview
be removed from the scrollviews array
of subviews
?
NSArray *viewsToRemove = [scrollView subviews];
for (UIView *v in viewsToRemove) [v removeFromSuperview];
你可以这样做,
[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
This will remove all subviews of a UIScrollView but its scroll indicators: _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; [_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = YES;
for (UIView *v in [scrollView subviews]) {
[v removeFromSuperview];
}
Swift
for subview in scrollView.subviews {
subview.removeFromSuperview()
}
在子视图上调用-removeFromSuperview。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.