ios - Image View is Causing Awkward Hang? -


i've been working on couple days (off & on) , i'm not exactly sure why isn't working, i'm askin pros @ sof insight.

newsitem.m

on first view controller, i'm reading json feed has 10+ items. each item represented newsitem view allows title, body copy, , small image. uiimageview has iboutlet called imageview. i'm loading image imageview asynchronously. when image loaded, i'm dispatching notification called image_loaded. notification picked on the newsitemarticle

dispatch_queue_t concurrentqueue = dispatch_get_global_queue(dispatch_queue_priority_default, 0); //this start image loading in bg dispatch_async(concurrentqueue, ^{     nsdata *image = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:self.imageurl]];     //this set image when loading finished     dispatch_async(dispatch_get_main_queue(), ^{         [self.imageview setalpha:0.0];         self.image = [uiimage imagewithdata:image];         [self.imageview setimage:self.image];         [uiview animatewithduration:0.5 animations:^{             [self.imageview setalpha:1.0];         }];          if(self)         [[nsnotificationcenter defaultcenter] postnotificationname:image_loaded object:self];     }); }); 

newsitemarticle.m

when user taps on newsitemview load new controller scroll view of several newsitemarticle views inside scrollview. newsitemarticle listen image_loaded , if decided current notification has image particular article, use same image it's own reference so:

- (void)handleimageloaded:(nsnotification *)note {     if([note.object isequal:self.cell]) {         // next line hanging app. not sure why.         [self.imageview setimage:self.cell.image];         [self.activityviewindicator removefromsuperview];     } } 

so essentially:

  • i'm using asynchronous load on first image reference
  • i'm using notifications let other parts of app know , image loaded
  • the app hangs when existing image reference second uiimageview

if comment out suspect line, app never hangs. its, app hangs until images loaded. thoughts are:

  1. this network threading conflict (not likely)
  2. this gpu threading conflict (perhaps during resize container view's size?)

has seen before?

for lazy loading of table view images there few options available. can make use of them in design save time , avoid efforts reinvent wheel.
1. apple lazy loading code --link
2. sdwebimage --link

sdwebimage provide completion handler/block can use notification mechanism notify other modules of application.

cheers!
amar.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -