我有一些代碼,如下圖所示:顯示文本
- (IBAction)startButtonPressed:(id)sender {
statusText.text = @"Processing...";
//here I do a bunch of calculations
//display calculated data
statusText.text = [[NSString alloc] initWithFormat:@"coefficient: %.4f",
[[coefficientEstimatesR objectAtIndex:0] doubleValue]];
}
,我這樣做需要大約17S的計算,所以我想顯示單詞「處理」,而這是正在完成。但是,當我運行這個時,「處理」從不顯示,只顯示計算的數據。
任何想法如何做到這一點,將不勝感激。 謝謝!
這是完美的,非常感謝你! – exolaris 2012-03-22 21:32:56
有沒有辦法讓它在while循環中工作?我一直在嘗試沒有成功。 (我想無限期地運行計算,因爲我們試圖查看在ipad/ipod死亡之前我們可以運行這個應用程序多少次,這是出於研究目的,並且我需要打印迄今完成的迭代次數以及每次通過while循環計算係數)。 – exolaris 2012-03-22 21:55:15
看到內部調用dispatch_async()?您可以隨時通過計算代碼更新狀態。你會很好地閱讀GCD - 一旦你理解它就很容易使用。 – Caleb 2012-03-22 22:15:26