以编程方式删除UIScrollView中的内容?

Pop*_*eye 3 iphone objective-c uiscrollview ios

如何以编程方式删除UIScrollView中的内容?因为我必须经常更新其中的内容.

ber*_*ium 6

我不认为典型的UIView之间存在差异:

for (UIView *v in [scrollView subviews])
    [v removeFromSuperView];
Run Code Online (Sandbox Code Playgroud)


小智 6

您可以循环滚动视图的子视图,如:

for(UIView *subview in scrollView.subviews)
    [subview removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)

或者您可以使用如下- [NSArray makeObjectsPerformSelector:]方法:

[scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
Run Code Online (Sandbox Code Playgroud)


Div*_*ert 5

for(UIView *vw in [scrView subViews])
  [vw removeFromSuperView];
Run Code Online (Sandbox Code Playgroud)

您可以使用它来删除滚动视图中的内容