任何人都可以幫我performSelectorInBackground
?我想用performSelectorInBackground
中的更新數據重新載入表格。IPhone + performselector在後臺
0
A
回答
4
你可以做的只是在後臺線程中獲取數據,一旦獲取數據並更新主線程中的tableview,就可以返回主線程。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//All your views cell creations and other stuff
[self performSelectorInBackground:@selector(loadDataThatToBeFetchedInThread:)
withObject:objectArrayThatNeedToFetchData];
}
- (void) loadDataThatToBeFetchedInThread:(NSArray *)objectThatNeedToFetchData
{
//Fetch the data here. which takes place in background thread
[self performSelectorOnMainThread:@selector(updateTableViewWithTheData:)
withObject:responseData
waitUntilDone:YES];
}
- (void) updateTableViewWithTheData:(NSMutableArray *)yourData
{
//Update Data to tableview here
}
+0
對不起,我只能給一個+1 :) – 2012-03-20 09:23:07
+0
^非常感謝,我一定會試一試 – Shantanu 2012-03-20 11:37:19
0
所有的UI功能都應該在主線程中完成。所以你必須在主線程中重新加載UITableView。
+0
看起來像一個很棒的評論!但也許你看看這個問題! – 2015-04-29 09:54:38
相關問題
- 1. IPhone performSelector issue
- 2. 在For循環中使用performSelector? iPhone
- 3. (iphone)pushViewController在後臺線程?
- 4. 需要在performSelector之後調用NSAutoReleasePool:withObject:afterDelay?
- 5. iPhone如何取消停止performSelector
- 6. Performselector在NSThread
- 7. iPhone:重複後臺任務
- 8. iphone後臺應用程序
- 9. Iphone 4.0 - 後臺計時器
- 10. iphone定時器倒計時在後臺
- 11. iPhone應用程序在後臺
- 12. iOS iPhone在後臺發現GKSession
- 13. iPhone - 如何在後臺執行任務?
- 14. 在後臺請求iPhone的位置?
- 15. iPhone:停止在後臺運行程序
- 16. 在後臺iPhone跟蹤距離
- 17. DataMan iPhone App如何在後臺工作
- 18. 如何在iPhone的後臺運行sqlite?
- 19. 在後臺上傳iPhone圖片
- 20. 在後臺播放音頻(iPhone OS 4.0)
- 21. IPhone AudioStreamer不能在後臺工作OS4
- 22. iPhone停止在後臺播放音頻
- 23. iphone應用程序在後臺運行?
- 24. iPhone iOS4-在後臺播放鬧鐘?
- 25. iPhone - 讓收音機在後臺運行
- 26. 在後臺加載OpenGl視圖。 iPhone
- 27. 在iPhone的後臺發送郵件
- 28. 在後臺播放電臺
- 29. iOS,iPhone快照在後臺/前臺轉換中
- 30. 未在iPhone 5和7 Plus中調用performSelector
後臺沒有UI更新。 UI更改必須在主線程上執行。 – lukya 2012-03-20 09:12:31