ios - Threading loading images from a device to a tableView in swift -


i can't find online threading loading image device , scrolling smoothly through tableview. there 1 on ray wen this, doesn't me situation.

does have advice or code allow tableview scroll smoothly , load images device's temporary directory?

i did mentioned @ tutorial, modification nsoperation subclass

this methods fetch

-(void) updatedata {       [self.pendingoperations.downloadqueue addoperationwithblock:^{         nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);         nsstring *documentsdirectory = [paths objectatindex:0];         nsarray *filepathes = [self recursiverecordsforresourcesoftype:@[@"png", @"jpeg", @"jpg",@"pdf"] indirectory:documentsdirectory];         @synchronized (self) {             self.documents = filepathes;             nslog(@"documents count %@", @([self.documents count]));         }         dispatch_async(dispatch_get_main_queue(), ^(void){             //run ui updates             [self.delegate modeldidupdate:self];         });      }];   }  - (nsarray *)recursiverecordsforresourcesoftype:(nsarray *)types indirectory:(nsstring *)directorypath{      nsmutablearray *filepaths = [[nsmutablearray alloc] init];      nsmutabledictionary *typesdic = [nsmutabledictionary dictionary];     (nsstring *type in types)          [typesdic setobject:type forkey:type];      // enumerators recursive     nsdirectoryenumerator *enumerator = [[nsfilemanager defaultmanager] enumeratoratpath:directorypath];      nsstring *filepath;      while ((filepath = [enumerator nextobject]) != nil){          // if have right type of file, add list         // make sure prepend directory path         if([typesdic objectforkey:[filepath pathextension]]){             //[filepaths addobject:[directorypath stringbyappendingpathcomponent:filepath]];             curfilerecord *record = [curfilerecord new];             record.filepath =[directorypath stringbyappendingpathcomponent:filepath];             record.filename = filepath;             [filepaths addobject:record];         }     }       return filepaths; } 

this .m subclass

- (void)main {      // 4     @autoreleasepool {          if (self.iscancelled)             return;         nsdata *filedata = [[nsfilemanager defaultmanager] contentsatpath:self.filerecord.filepath];        // self.filerecord.filedata = filedata;         if (self.iscancelled) {             filedata = nil;             return;         }          if (filedata) {             uiimage *newimage;             if ([[self.filerecord.filepath pathextension] isequaltostring:@"pdf"])             {                 cgpdfdocumentref doc = [curdocumentviewerutilities mygetpdfdocumentref:filedata];                 newimage = [curdocumentviewerutilities buildthumbnailimage:doc withsize:cgsizemake(64, 96)];             }             else             {                 newimage = [curdocumentviewerutilities makepreviewimagefromdata:filedata];             }             self.filerecord.previewimage = newimage;         }         else {             self.filerecord.failed = yes;         }          filedata = nil;          if (self.iscancelled)             return;          // 5         [(nsobject *)self.delegate performselectoronmainthread:@selector(imagedownloaderdidfinish:) withobject:self waituntildone:no];      } } 

with update func i've fetched pathes proccess, , nsoperation subclass loads images. works fine 2000 images in fullhd - smoothly , without lugs


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -