我認爲performSelector:withObject:afterDelay
將幫助你在這裏。
編寫一個可以增加進度條的方法。在該方法結束時,用相同的方法調用performSelector:withObject:afterDelay
,延遲1秒,直到條滿。
您可能不需要將對象傳遞給該方法,因此您可以使用nil。
編輯
在你的情況我建議是這樣的:
- (IBAction)startProgressBar:(id)sender
{
// Initialize the progress bar to go from 0 to 100
[progress setMinValue:0.0];
[progress setMaxValue:100.0];
[progress setDoubleValue:0.0];
// Start the auto-increment calls
[self incrementProgressBar];
}
- (void)incrementProgressBar
{
// Increment the progress bar value by 1
[progress incrementBy:1.0];
// If the progress bar hasn't reached 100 yet, then wait a second and call again
if([progress doubleValue] < 100.0)
[self performSelector:@selector(incrementProgressBar) withObject:nil afterDelay:1];
}
我已經知道該行的代碼,但我不知道它,請如何循環給我更多的細節: ) – CocoaCoder 2012-02-27 18:32:53
想象一下,您在最後編寫了一行代碼。該方法運行後,它將再次運行(延遲後)。然後再次。它有點像遞歸方法。 – Aaron 2012-02-27 20:18:23
是的,但我想讓它循環,直到條100%滿,那麼我想停止循環,請幫助:D – CocoaCoder 2012-03-01 19:22:49