2

I have attached a new thread and in that thread I'm firing 5 SQLite queries.

Problem is that until execution of all my queries is finished, I'm not able to scroll the table view. It freezes for some seconds.

-(void)viewDidAppear:(BOOL)animated
{
    [NSThread detachNewThreadSelector:@selector(GetBackEndData) 
        toTarget:appDelegate withObject:nil];
}

// this is in appDelegate
-(void)GetBackEndData
{   
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    if([dicBarnearMe_Detail count]==0)
    {
        // this are sql queries method.
        [appDelegate SelectBeersonbottle_Count];
        [appDelegate SelectBeersonTap_Count];
        [appDelegate SelectGrowler_Count];
        [appDelegate SelectHappyHours_Count];
        [appDelegate SelectEvents_Count];

        // After completing this process I'm post notification 
        // for reloading table in other controller.
        [[NSNotificationCenter defaultCenter] postNotificationName:@"reload" 
            object:nil userInfo:nil];
    }

    [pool release];     
}
ruyamonis346
  • 357
  • 3
  • 15

1 Answers1

0

You are making a new thread in viewDidAppear and executing the GetBackEndData selector in separate thread.

[[NSNotificationCenter defaultCenter] postNotificationName:@"reload" object:nil userInfo:nil];

you making NSNotificationCenter in GetBackEndData and reloading some data that means you have to wait until your thread complete the execution and blocking UI thread.

making a thread in viewDidAppear is not a right approach you can use a dispatchQue in some other function or alternative option is wait until your thread execution get completed and show activity Indicator.

Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54
Jignesh Agola
  • 320
  • 1
  • 11