2014-05-20 4 views
0

재로드, 난 테이블을로드 할 때 나는 빈 데이터 소스를 , 그 후 나는 서버 에서 데이터를 얻을 때 나는이 [tableview reloadData] 하지만, numberOfRowsInSectionCellForRowAtIndexPath bettwen 큰 지연이 나의 테이블 모양의 동결을 지금 시간에는. 아무도 나를 도와 줄 수 없어!내가 문제가있는 jQuery과

2014-05-20 14:07:02.803[8097:4f03] didReceivePlaces 
2014-05-20 14:07:02.809[8097:4f03] numberOfRowsInSection 
2014-05-20 14:07:13.310[8097:4f03] cellForRowAtIndexPath 
2014-05-20 14:07:13.352[8097:4f03] cellForRowAtIndexPath 
2014-05-20 14:07:13.368[8097:4f03] cellForRowAtIndexPath 
2014-05-20 14:07:13.383[8097:4f03] cellForRowAtIndexPath 
2014-05-20 14:07:13.397[8097:4f03] cellForRowAtIndexPath 

편집 내가 같이 메인 스레드에서 테이블을 다시로드해야 답을 찾을 수 그 작업 훌륭한! [표 performSelectorOnMainThread : @ 선택기 (reloadData) withObject : nil waitUntilDone : 예];

+0

추가 한 메시징 로그는 어디에 문제가 좁혀 충분하지 않습니다. '[tableView reloadData]'를 어디에서 호출하는지 알려주십시오. UI를 차단하고있는 주 스레드에서 실행중인 다른 작업이있는 것 같습니다. – Pancho

+0

예, 맞습니다! 나는 같은 시간에 서버와 함께 일하므로 사용법을 찾는데 도움이된다. [표 performSelectorOnMainThread : @selector (reloadData) withObject : nil waitUntilDone : YES]; –

+0

모든 UI 업데이트는 주 스레드에서 수행됩니다. 백그라운드에서 UI를 업데이트하려고하면 예외가 발생합니다. 유일한 해결 방법은 백그라운드로 웹 서비스 요청을 실행하는 것이고, 응답을 받으면 메인 스레드에서'tableView'를 업데이트하면됩니다. 나는 잠시 후에 당신에게 모범을 보일 것이다. – Pancho

답변

1

응답이 수신 될 때까지 당신의 UI가 차단 된 웹 서비스에 URLRequest를 전송하는 동안. 해결 방법은 UI를 차단하지 않도록 별도의 스레드에서 요청을 실행하는 것입니다.

예 :

NSString *urlStr = @"http://www/yourwebsite.com/webservice/"; 
NSString *postString = @"username=Username&pass=123545"; 
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init]; 
[request setURL:[NSURL urlQithString:urlStr]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 

// create NSOperationQueue for your webservice call 
NSOperationQueue *queue = [[NSOperationQueue alloc]init]; 

// rnu your webservice call on the separate operation queue with completion block 
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError){ 

// do whatever you have to do when webservice returns data 


//update your tableview on the main thread at the end 
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
     [tableView reloadData]; 
    }]; 

}]; 
+0

자세한 답변을 부탁드립니다! –

+0

당신은 환영합니다 – Pancho

0

메인 스레드에서 UITableView를 다시로드 해보십시오. UI 업데이트는 항상 주 스레드에서 수행되어야합니다.

dispatch_async(dispatch_get_main_queue(), ^{ 
        [tableview reloadData]; 
     })