04-29-2011, 12:08 AM
|
#12 (permalink)
|
|
Registered Member
Join Date: May 2010
Posts: 1
|
Quote:
Originally Posted by BrianSlick
The first one failed because subviews is not a property of self, which is presumably your view controller. If this was a custom UIView subclass, it would probably work.
The second failed because it isn't approaching the problem correctly. If you are making the array smaller each time, you have to work backwards. If you remove the object at index 0, then the object that was at index 1 is now at index 0. But your next pass removes the object at index 1, and so on.
I'm a little surprised that the 3rd one worked, because you can't change the size of the array when doing fast enumeration. I'm going to guess that it works here because the subviews property returns a copy of the array, so you aren't messing with the actual subview array.
Somebody posted a cool array trick here a few weeks ago. I haven't tested this code, but it should be something like this:
Code:
[[[self view] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
|
this is a good way.
|
|
|