how to remove subviews from scrollview?

后端 未结 8 2232
时光取名叫无心
时光取名叫无心 2020-12-02 09:10

how do i remove all subviews from my scrollview...

i have a uiview and a button above it in the scrollview something like this....

here is my code to add sub

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 09:23

    I don't think you should use the fast enumeration suggestion.

    for(UIView *subview in [view subviews]) {
       [subview removeFromSuperview];
    }
    

    Isn't this supposed to throw an exception if you change the collection being iterated? http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocFastEnumeration.html#//apple_ref/doc/uid/TP30001163-CH18-SW3

    This example may be better.

    NSArray *subviews = [[scroller subviews] copy];
    for (UIView *subview in subviews) {
        [subview removeFromSuperview];
    }
    [subviews release];
    

提交回复
热议问题