Cancelling loading data in uitableview in iphone
In my app i have a large number , around 70000 records to load in a tablevie开发者_高级运维w. It takes a lot of time to load like ten minutes. Since it blocks the main UIthread, I am unable to go back or access any buttons. Is there any alternate way like using a separate thread for this purpose or any alternate approach ? Please show me some way.
Thanks, Vinod.
Use a NSThread.
Your code will look something along the lines of:
NSThread *thread = [NSThread initWithTarget:self selector:@selector(loadData:) object:nil];
[thread start];
[thread release];
-(void) loadData:(id) obj {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// load data
[pool release];
}
If you need to do anything on the main UI thread from the newly created thread, use the performSelectorOnMainThread:withObject
method on the current object.
精彩评论