1
A
回答
5
您可以使用GCD。這裏是Raywenderlich tutorial
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
//Calculations
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI must be here
});
});
}
2
viewDidLoad:
視圖加載時觸發。這與顯示視圖時不同。
請嘗試開始- (void)viewDidAppear:(BOOL)animated
回調方法中的計算,而不是UIViewController
。
如果這些計算需要一段時間,考慮在後臺線程上運行它們。這將防止UI在計算運行時被鎖定。這不僅可以讓視圖顯示,而且可以在用戶等待時與其交互。
[self performSelectorInBackground:@selector(doCalc)
withObject:nil];
從這doCalc
方法,你會回調,結果主線程。
[self performSelectorOnMainThread:@selector(didCalcValue:)
withObject:result
waitUntilDone:NO];
2
正如其他人正確地指出,viewDidAppear
咱們你知道什麼時候該觀點已經出現在屏幕上。 *另外,當您使用這些事件方法時,請不要忘記撥打super
。
實施例:
// Tells the view controller that its view was added to the view hierarchy.
- (void)viewDidAppear:(BOOL)animated
{
// makes sure it's also called on the superclass
// because your superclass may have it's own code
// needing to be called here
[super viewDidAppear:animated];
// do your calculations here
}
常用的UIViewController事件:
– (void)viewDidLoad
調用在存儲器當你的視圖首次加載。
– (void)viewDidAppear:
在您的視圖出現在屏幕上後調用。
– (void)viewWillDisappear:
調用之前您的視圖將從屏幕上消失。
請參閱關於UIViewController Class Reference page的完整列表。
相關問題
- 1. iphone;只有在視圖出現之後才做東西..觀看會出現嗎?
- 2. iOS:滾動視圖只有在出現鍵盤後才起作用
- 3. ScrollView只在第二次顯示視圖時纔開始滾動
- 4. 只有在被NFC調用後才能開始活動
- 5. 只有在完整視頻緩衝後纔開始播放HTML5視頻
- 6. 只有當我觸摸屏幕後纔開始動畫
- 7. 只有當特定視圖不出現時才彈出視圖控制器
- 8. 從現在開始計算幾個月
- 9. 只有觸動開始後什麼?
- 10. Tableview只在我離開視圖後才更新並且回來
- 11. 如何在按下按鈕之後纔開始運行視圖?
- 12. iPhone視圖出現在動畫背後
- 13. 從現在開始計算6年後的日期?
- 14. 只有在mozila纔會出現錯誤
- 15. Android:出現錯誤「只有創建視圖層次結構的原始線程才能觸及其視圖」
- 16. 自動加計數開始
- 17. 只有在處理完成後纔會出現resignFirstResponder
- 18. 打開自動計算
- 19. deinit只有在視圖控制器打開時才被調用
- 20. 從哪裏開始計算機視覺
- 21. 只有當物體移動或計算不斷時才計算交點
- 22. 只有在更改JFrame的大小後才更新視圖
- 23. 只有在視圖成功完成後才能保存Django
- 24. 計算stl開始()
- 25. 只有在通知出現後纔會觸發火災行動(swift3)
- 26. 只有在日期已過時才計算總計值
- 27. 只有在首次啓動時纔會出現decisionPolicyForNavigationAction錯誤IPad
- 28. 如何在呈現視圖後開始加載WebView?
- 29. 自定義滾動視圖不出現
- 30. 從現在開始計算分鐘數,直到出現某種情況
線程計算 – rooster117 2013-03-22 18:35:30