iphone asynchronous file load?
is there way to load local files in iphone asynchronously? I load uiimages for my uitableview using this:
NSData *imageData = [[NSData alloc] initWithContentsOfFile:fileName];
UIImage *cachedImage = [[[UIImage alloc] initWithData:imageData] autorelease];
but it is slow, because main thread is locked or something until NSData finishes loading the file and UI becomes unresponsive. Is there something like NSURLConnection but for 开发者_开发问答local files? So I can just load file without freezing UI, and when it finishes loading, some handler sends notification or something like that.
You can use an NSOperationQueue and NSInvocationOperation to call a 'load' procedure. Then, from the load procedure, simply use the 'performSelectorOnMainThread' to update. See: http://gist.github.com/375559 for a detailed example.
精彩评论