views:

54

answers:

1

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.

+3  A: 

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.

Kevin Sylvestre
thanks, I'll try that
Mike