看板 MacDev 關於我們 聯絡資訊
想問一個關於CoreData的Fetch和GCD的問題 因為我的database有11萬筆資料 所以我在AppDelegate 的didFinishLaunchingWithOptions: 裡面用GCD進行Fetching ==in AppDelegate -application:didFinishLaunchingWithOptions: // 把fetchRC的delegate設為tableVC self.fetchedResultsController.delegate = self.tableViewController; // 用GCD進行fetch dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSError *error = nil; if (![self.fetchedResultsController performFetch:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } self.fetchObjects = [self.fetchedResultsController fetchedObjects]; // 加入這行之後 tableView才會更新 [self.tableViewController.tableView reloadData]; }); == 這樣的話App開啟的時候會直接顯示我的table view 但是等fetch跑完之後table view的data並沒有更新 tableViewController裡面的NSFetchedResultsControllerDelegate methods被沒有被呼叫 於是我在GCD裡的最後一行 加入了reloadDta強迫tableView重新載入資料 但是reloadData執行完後 table view卻等了5秒鐘才更新 請問 1) NSFetchedResultsControllerDelegate methods沒被呼叫是正常的嗎? 2) 有沒有辦法加速在reload完之後 更新tableView的速度? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.45.233 ※ 編輯: leondemon 來自: 60.198.45.233 (09/11 03:34)
dryman:跟view相關的要丟到main queue裡面做 09/11 06:50
dryman:你可以把tableView reloadData那行用dispatch_async 09/11 06:51
dryman:dispatch_get_main_queue() 包起來 09/11 06:51
leondemon:thanks! 09/11 17:00