开发者

Cancelling loading data in uitableview in iphone

开发者 https://www.devze.com 2023-03-09 07:32 出处:网络
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

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.

0

精彩评论

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