Iphone 在线程中激发sql查询时,表视图冻结
我附加了一个新线程,在该线程中我触发了5个SQLite查询 问题是,在完成所有查询之前,我无法滚动表视图。它冻结了几秒钟Iphone 在线程中激发sql查询时,表视图冻结,iphone,uitableview,ios4,iphone-sdk-3.0,nsthread,Iphone,Uitableview,Ios4,Iphone Sdk 3.0,Nsthread,我附加了一个新线程,在该线程中我触发了5个SQLite查询 问题是,在完成所有查询之前,我无法滚动表视图。它冻结了几秒钟 -(void)viewDidAppear:(BOOL)animated { [NSThread detachNewThreadSelector:@selector(GetBackEndData) toTarget:appDelegate withObject:nil]; } // this is in appDelegate -(void)GetB
-(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];
}
您正在
视图中创建一个新线程,并在单独的线程中执行GetBackEndData
选择器
[[NSNotificationCenter defaultCenter]postNotificationName:@“重新加载”
对象:nil userInfo:nil]代码>
您在GetBackEndData
中创建NSNotificationCenter
,并重新加载一些数据,这意味着您必须等待线程完成执行并阻塞UI线程
在ViewDidDisplay中创建线程不是一种正确的方法。您可以在其他一些函数中使用dispatchQue,或者其他选项是等待线程执行完成并显示活动指示器。您正在ViewDidDisplay中创建一个新线程,并单独执行GetBackEndData
选择器线
[[NSNotificationCenter defaultCenter]postNotificationName:@“重新加载”
对象:nil userInfo:nil]代码>
您在GetBackEndData
中创建NSNotificationCenter
,并重新加载一些数据,这意味着您必须等待线程完成执行并阻塞UI线程
在ViewDidDisplay中创建线程不是一种正确的方法。您可以在其他函数中使用dispatchQue,或者其他选项是等待线程执行完成并显示活动指示器。让我们看看sql查询方法中的内容……您在主线程上做什么?我已经尝试对这一新线程行及其干得好。所以,问题是附加执行sql查询的新线程。在主线程上,我只是在重新加载表。让我们看看sql查询方法中有什么……你们在主线程上做什么?我试着对这个新线程行进行注释,它的工作很好。所以,问题是附加执行sql查询的新线程。在主线程上,我只是在重新加载表。