ios - Iterating an NSMutableDictionary with UIImage not working -
i trying add images fetched external service nsmutabledictionary , seeing weird results. doing:
- (void)fetchimages{ //fetch item brand images //self.itembrands nsarray of nsdictionaries (nsdictionary *itembrand in self.itembrands){ nsstring *currentitemid = [itembrand objectforkey:@"item_id"]; //valid item id. log message displayed nslog(@"current item id: %@",currentitemid); nsstring *currentitemimageurl = [[image_url stringbyappendingstring:currentitemid] stringbyappendingstring:@".png"]; //image url valid. log message displayed nslog(@"current image url: %@",currentitemimageurl); nsurl *url = [nsurl urlwithstring:currentitemimageurl]; nsdata *data = [nsdata datawithcontentsofurl:url]; uiimage *image = [uiimage imagewithdata:data]; if (image == nil){ //this log message displayed when image not present nslog(@"image not present 1"); }else{ //this log message displayed when image present nslog(@"image present 1"); [self.itembrandimages setobject:image forkey:currentitemid]; } } //this loop not being executed @ all. no log messages displayed. for(id key in self.itembrandimages){ nslog(@"current item id2: %@",key); if ([self.itembrandimages objectforkey:key] == nil){ nslog(@"image not present 2"); }else{ nslog(@"image present 2"); } } }
the 2nd loop iterating on self.itembrandimages not being executed @ all. none of log messages inside being displayed.
i tried following before posting issue here:
1) researched similar problems in stack overflow , incorporated suggestion 1 of them. suggestion "perform alloc init of nsmutabledictionary" in init method of .m file. didn't either.
2) isolate issue, tried adding simple string nsmutabledictionary instead of image not seem retained.
i confused as missing or doing wrong here. inputs appreciated.
thanks, mike g
perhaps:
for(nsstring *key in [self.itembrandimages allkeys])
Comments
Post a Comment