How do you remove the content in a UIScrollView Programmatically? As I have to update the content in it frequently.
Asked
Active
Viewed 2,384 times
4
-
just use the `scrollView = nil` and `scrollView = [UIScrollView alloc] init];` – The iOSDev Apr 11 '12 at 11:59
-
1Possible duplicate of http://stackoverflow.com/questions/1310723/how-to-remove-subviews-from-scrollview – Gray Apr 11 '12 at 14:46
-
@Gray I believe you are correct. I believe I could have found my answer in there. But I spent quite a long time looking for the answer to this an never came across it. But I was searching for removing content from the UIScrollView not the subviews so that is probably why I didn't find it. Thanks +1. – Popeye Apr 11 '12 at 14:58
-
Np @john. I was just adding that for posterity. – Gray Apr 11 '12 at 15:00
4 Answers
6
I don't think that there is a difference between typical UIView:
for (UIView *v in [scrollView subviews])
[v removeFromSuperView];

beryllium
- 29,669
- 15
- 106
- 125
5
for(UIView *vw in [scrView subViews])
[vw removeFromSuperView];
You can use this to remove contents in your scrollview

DivineDesert
- 6,924
- 1
- 29
- 61
5
You can loop through your scroll view's subviews like:
for(UIView *subview in scrollView.subviews)
[subview removeFromSuperview];
or you can use - [NSArray makeObjectsPerformSelector:]
method like:
[scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

neilvillareal
- 3,935
- 1
- 26
- 27
4
Following code is use to remove object in scroll view
[[myScrollView viewWithTag:myButtonTag] removeFromSuperview];

Nimit Parekh
- 16,776
- 8
- 50
- 72