ios - Remove a custom MKOverlayView -


i'm using subclassed mkoverlay , subclassed mkoverlayview display wms tiles. got running well.

i'm running issue of removing mkoverlayview when i'm done displaying tiles. can remove mkoverlay fine:

-(void)removewmsoverlay {         (wmsoverlay *overlay in self.mapview.overlays) {         if ([overlay iskindofclass:[wmsoverlay class]]) {                         mkoverlayview *test = [self.mapview viewforoverlay:overlay];              [self.mapview removeoverlay:overlay];         }     } } 

but wmsoverlayview still there , still running code (constantly checking if new tiles can draw) creates lag.

i don't know find list of mkoverlayviews active. tried:

-(void)removewmsoverlay {         (wmsoverlay *overlay in self.mapview.overlays) {         if ([overlay iskindofclass:[wmsoverlay class]]) {                         mkoverlayview *test = [self.mapview viewforoverlay:overlay];              [self.mapview removeoverlay:overlay];              [test removefromsuperview];              test = nil;         }     } } 

to no effect. code still running.

even tried keep reference of around nil:

- (mkoverlayview *)mapview:(mkmapview *)mapview viewforoverlay:(id <mkoverlay>)overlay {     if ([overlay iskindofclass:[wmsoverlay class]]) {          wmsoverlayview *view = [[wmsoverlayview alloc] initwithoverlay:overlay];         view.alpha = .8;          self.wmsoverlayview = view;          return view;     }      return false; }  -(void)removescene {         (wmsoverlay *overlay in self.mapview.overlays) {         if ([overlay iskindofclass:[wmsoverlay class]]) {                         [self.mapview removeoverlay:overlay];              self.wmsoverlayview = nil;         }     } } 

can remove mkoverlayview or need figure out how reuse view?

edit:

i tried reusing mkoverlayview:

else if ([overlay iskindofclass:[wmsoverlay class]]) {     self.wmsoverlayview = [[wmsoverlayview alloc] initwithoverlay:overlay];      return self.wmsoverlayview; } 

and added timer show more 1 mkoverlayview runing:

-(void)amistillhere {     dlog("i'm still running | self: %@", self); } 

they don't reused or go away:

 debug | -[wmsoverlayview starttimer] | i'm still running | self: <wmsoverlayview: 0x1d84afe0; frame = (6.02801e+07 9.44092e+07; 2.30324e+06 2.10344e+06); opaque = no; layer = <mkoverlayclusterproxylayer: 0x21bf3ff0>>  debug | -[wmsoverlayview starttimer] | i'm still running | self: <wmsoverlayview: 0x21be1a80; frame = (6.06487e+07 9.2838e+07; 2.36776e+06 2.15038e+06); opaque = no; layer = <mkoverlayclusterproxylayer: 0x1d8e2a20>> 

curious, added nscachedelegate see when item evicted (i concerned having nscache each wmsoverlayview , how behave , memory usage, set cache 32mb , don't want gobble memory). tried naming each cache see if there 2 caches, see if old cache cleared out make room in memory newer cache. realized each cache named same:

-(mkoverlayview *)mapview:(mkmapview *)mapview viewforoverlay:(id <mkoverlay>)overlay {     if (self.wmsoverlayview == nil) {         self.wmsoverlayview = [[wmsoverlayview alloc] initwithoverlay:overlay withcachename:@"cache!"];     }     else {         self.wmsoverlayview = [[wmsoverlayview alloc] initwithoverlay:overlay withcachename:@"the new better cache!"];     }      return self.wmsoverlayview; } 

i noticed self.wmsoverlayview nil , naming cache cache!. wmsoverlayview removed when overlay removed. timer kept going off. refactored code remove timer , when removed wmsoverlay, cache cleared out (got cache:willevictobject: nslog spammed).

so believe timer keeping wmsoverlayview alive.

moral of story: don't place timer in mkoverlayview.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -