Friday, 15 March 2013

iphone - Collection was mutated while being enumerated -



iphone - Collection <CALayerArray: 0x1ed8faa0> was mutated while being enumerated -

my app crashes time while removing wait view screen. please guide me how can improve code given below.

the wait view called when app downloading server. , when completed download phone call removewaitview method.

exception type: nsgenericexception

reason: collection mutated while beingness enumerated.

+(void) removewaitview:(uiview *) view{ nslog(@"shared->removewaitview:"); uiview *temp=nil; temp=[view viewwithtag:kwaitviewtag]; if (temp!=nil) { [temp removefromsuperview]; } }

my waitview adding code is

+(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]; }

the exception pretty clear - collection (in case array) beingness modified while beingness enumerated.

in specific case talking array of layers, or improve said, instances of uiview backed layers.

the modifications happen when calling removefromsuperview or addsubview. enumeration can happen anytime during redrawing.

my guess - not calling methods main thread , main thread redrawing, you'll racing condition.

solution: phone call these methods main thread.

iphone ios objective-c

No comments:

Post a Comment