Re: [問題] Core Data Fetch與GCD的問題

看板MacDev作者 (狗狗)時間11年前 (2012/09/11 17:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)

09/11 06:50,
跟view相關的要丟到main queue裡面做
09/11 06:50

09/11 06:51,
你可以把tableView reloadData那行用dispatch_async
09/11 06:51

09/11 06:51,
dispatch_get_main_queue() 包起來
09/11 06:51
謝謝D大幫我解決了 App開啟時load data的問題 但是目前遇到了另外一個狀況: 我做了一個字典的功能 並用searchBar可以搜尋單字 然後如法炮製(如下) // UISearchBarDelegate method - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) , ^{ NSPredicate *predicate = [NSPredicate predicateWithFormat: @"word BEGINSWITH %@", searchText]; self.searchObjects = [self.fetchedResultsController.fetchedObjects filteredArrayUsingPredicate:predicate]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); }); } 結果是cell.textLabel.text的資料是有更新 但畫面上的table cell卻沒有更新 變成要手動捲動table view時cell的textLabel才會更新 當我打"b"的時候 tableView第一個cell 依然是A開頭的字 當我打"bo"的時候 tableView第一個cell 是b 當我打"boy"的時候 tableView第一個cell 指出現是bo 也就都是上一個搜尋的結果 請問這個問題要怎麼解決呢? ===== 自問自答: 我忘了實際顯示的table不是原來的那一個 應該是searchDisplayController.searchResultsTableView 的這個tableView做reload -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 42.72.144.20 ※ 編輯: leondemon 來自: 42.72.144.20 (09/11 17:40) ※ 編輯: leondemon 來自: 42.72.144.20 (09/11 17:59)
文章代碼(AID): #1GJmNiox (MacDev)
文章代碼(AID): #1GJmNiox (MacDev)