The <CALayerArray: 0x1ed8faa0> collection was mutated when enumerated

My application crashes for a while, removing the look of waiting from the screen. See how I can improve the code below.


The wait view is only called up when the application downloads something from the server. and when it finishes loading, I call the removeWaitView method.

Exception Type : NSGenericException

Reason: The collection was mutated when enumerated.

+(void) removeWaitView:(UIView *) view{
    NSLog(@"Shared->removeWaitView:");
    UIView *temp=nil;
    temp=[view viewWithTag:kWaitViewTag];
    if (temp!=nil) {
        [temp removeFromSuperview];
    }
}

my waitview add code

 +(void) showWaitViewInView:(UIView *)view withText:(NSString *)text{
   NSLog(@"Shared->showWaitViewWithtag");
   UIView *temp=nil;
   temp=[view viewWithTag:kWaitViewTag];
   if (temp!=nil)
   {
       return;
   }
   //width 110 height 40
   WaitViewByIqbal *waitView=[[WaitViewByIqbal alloc] initWithFrame:CGRectMake(0,0,90,35)];
   waitView.center=CGPointMake(view.frame.size.width/2,(view.frame.size. height/2) -15); 
   waitView.tag=kWaitViewTag;    // waitView.waitLabel.text=text;
   [view addSubview:waitView];
   [waitView release]; 
}
+5
source share
3 answers

The exception is pretty clear - the collection (in this case, something like an array) changes while it is also being listed.

, , UIView, .

, removeFromSuperview addSubview. .

- , , .

: .

+13

, , . , , , . , :

[[viewLayer.sublayers copy] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            CALayer * subLayer = obj;
            if(subLayer == theLayerToBeDeleted){
                [subLayer removeFromSuperlayer];
            }

        }];
+5

, waitView waitView ( subviews). , removeWaitView showWaitInView, , show/remove wait view for, ( waitView).

+3

All Articles