今天發現一個奇怪問題,當用NSNotification,在回調函數裏面對tableview進行reloadData時,並不能更新UI,而且還會導致以後都更新不了。後來查了一些資料才發現,postNotification之後調用回調函數,相當於開了一個子線程,而子線程中是不能更新UI的。所以要想在notification的回調裏面更新UI,必須用
dispatch_async(dispath_get_main_queue(),^{
[tableview reloadData];
}];
今天發現一個奇怪問題,當用NSNotification,在回調函數裏面對tableview進行reloadData時,並不能更新UI,而且還會導致以後都更新不了。後來查了一些資料才發現,postNotification之後調用回調函數,相當於開了一個子線程,而子線程中是不能更新UI的。所以要想在notification的回調裏面更新UI,必須用
dispatch_async(dispath_get_main_queue(),^{
[tableview reloadData];
}];