2012-02-08 5 views
2

새 스레드가 연결되어 있고 해당 스레드에서 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

+0

메인 스레드에서 뭐하고 있니? –

+0

나는이 새로운 스레드 라인과 그 작업에 대해 논평하려 노력했다. 그래서 문제는 SQL 쿼리 실행을 수행하는 새로운 쓰레드를 붙이는 것이다. 메인 스레드에서 테이블을 다시로드하는 중입니다. – ruyamonis346

답변

0

당신은 viewDidAppear에 새 스레드를 만들고 별도의 스레드에서 GetBackEndData 선택을 실행하고 있습니다.

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

당신은 GetBackEndData에서 NSNotificationCenter을하고 당신이 당신의 스레드가 실행 및 차단 UI 스레드를 완료 할 때까지 기다릴 필요가 의미 일부 데이터를 다시로드.

스레드를 viewDidAppear에서 만드는 것은 다른 방법으로 dispatchQue를 사용할 수있는 올바른 방법이 아니며 대체 옵션은 스레드 실행이 완료되고 작업 표시기가 표시 될 때까지 대기합니다.