开发者

iphone asynchronous file load?

开发者 https://www.devze.com 2023-01-04 10:41 出处:网络
is there way to load local files in iphone asynchronously? I load uiimages for my uitableview using this:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消