Remove subview UIImageview from UIScrollView

Hi, I have a uiscrollview and I have one uiimageview object inside a uiscrollview. I am running the application. then I scroll to the right in scrollview and scrollview changes, but I do not see the following uiimageview object that I add to - (void) scrollViewDidEndDecelerating: (UIScrollView *) scrollView. before adding the next object, I delete the previous one ... what is wrong?

delete the object i am using

UIImageView *l;

    for (NSInteger ko=0; ko<[[scroll subviews] count]; ko++){
        if ([[[scroll subviews] objectAtIndex:0] isKindOfClass:[UIImageView class]]){

            //This code never gets hit
            l=[[scroll subviews] objectAtIndex:0];
            [l removeFromSuperview];
            l=nil;

        }
    }

then I will add the following object

[scroll addSubview: imageView];

I delete the previous object because my application crashes when I add 110 images to the scrollview, so I need to manage the memory, I think. That is why I am deleting the previous object.

Help me please!

+3
2

, :

  • , , . , / 10 .

  • UIView - , . UIImageViews, , [UIView viewWithTag: tag]; .

  • st3fan . , " ", ObjectsInArray.

+2

, , , , . ko . 0.

:

NSArray* subviews = [[NSArray alloc] initWithArray: scroll.subviews];
for (UIView* view in subviews) {
    if ([view isKindOfClass:[UIImageView class]]) {
         [view removeFromSuperview];
    }
}
[subviews release];

, ?

+2

Source: https://habr.com/ru/post/1729696/


All Articles