데이터를 프리 페치하고 uitableview에 표시하는 데 문제가 있습니다. 그래서 기본적으로 웹에서 데이터를 가져올 수 있도록 기본 UI 스레드를 차단하고 싶습니다. 동기화를 위해 직렬 디스패치 대기열을 사용하고 있습니다. 또한 디스패치 대기열 블록은 웹에서 데이터를 가져 오는 다른 블록을 실행 중입니다. 실행 코드는 viewdidload로 작성됩니다.디스패치 대기열을 사용하여 주 스레드를 동기화하는 것과 관련된 문제가 발생했습니다.
dispatch_queue_t queue= dispatch_queue_create("myQueue", NULL);
CMStore *store = [CMStore defaultStore];
// Begin to fetch all of the items
dispatch_async(queue, ^{
[store allObjectsOfClass:[Inventory class]
additionalOptions:nil
callback:^(CMObjectFetchResponse *response) {
//block execution to fetch data
}];
});
dispatch_async(queue, ^{
//load data on local data structure
[self.tableView reloadData];
});
주 스레드 차단은 강력히 권장하지 않습니다. 웹에서 배경 스레드 (현재 수행중인 것처럼 보임)에서 데이터를로드하고 [tableView reloadData]를 호출 할 때 dispatch_get_main_queue로 디스패치하여 기본 대기열에 있는지 확인하십시오. – geraldWilliam