2012-02-08 47 views
2

我附加了一个新线程,并且在该线程中,我发射了5个SQLite查询。当sql查询在线程中被触发时表格视图冻结

问题是,直到执行完所有查询之后,我才能够滚动表视图。它冻结了几秒钟。

-(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];  
} 
+0

让我们看看有什么在SQL查询方法.... – Ankur 2012-02-08 13:28:49

+0

你在主线程上做什么? – 2012-02-08 13:35:52

+0

我已经尝试评论这个新的线程和它的工作正常。所以,问题是附加执行sql查询执行的新线程。在主线上我只是重新加载表。 – ruyamonis346 2012-02-09 10:14:46

回答

0

您在viewDidAppear作出新的线程来执行单独的线程GetBackEndData选择。

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

你在做GetBackEndDataNSNotificationCenter和重新加载一些数据,这意味着你必须等待,直到你的线程完成执行,并阻塞UI线程。

在viewDidAppear中创建一个线程是不正确的方法,您可以在其他函数中使用dispatchQue或者替代选项等待直到您的线程执行完成并显示活动指示符。