0

In my app i have a large number , around 70000 records to load in a tableview. 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.

Atom
  • 347
  • 2
  • 4
  • 12

1 Answers1

1

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.

csano
  • 13,266
  • 2
  • 28
  • 45
  • Its loading the tableview which blocks the main thread . Is there any alternate way for cancelling the loading in the middle ? Thanks ! – Atom May 31 '11 at 19:22
  • Yes, as long as you have a reference to the thread, you can cancel it by calling the `cancel` method. It sounds like you're trying to force all of the data to the UI thread at once. Have you tried splitting up the data? The user isn't going to be able to scroll through all 70,000 rows at once are they? – csano May 31 '11 at 19:26