2012-05-14 17 views
0

什麼我有是語義performSelectorOnMainThread的:withObject:waitUntilDone:

- (void)startTheBackgroundJob { 
    1.NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    2.[NSThread sleepForTimeInterval:3]; 
    3.[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:YES]; 
    4.//[self makeMyProgressBarMoving]; 
    5.[pool release]; 

} 

- (void)makeMyProgressBarMoving { 

    float actual = [threadProgressView progress]; 
    threadValueLabel.text = [NSString stringWithFormat:@"%.2f", actual]; 
    if (actual < 1) { 
     threadProgressView.progress = actual + 0.01; 
     [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO]; 
    } 
    else threadStartButton.hidden = NO; 

} 

在starTheBackgroundJob的行號4,您可以設置waitUntilDone = YES(或沒有)值。

予讀出的基準和它們表明:

等待

一個布爾指定是否當前線程塊之後在主 線程在接收器執行 與指定選擇直到。指定YES阻止此線程;否則,給 指定NO,立即返回此方法。 如果當前線程也是主線程,並且您爲此參數指定了YES,則會立即傳遞並處理消息 。

我的問題是:

  1. 什麼在這裏指定的選擇是(在這個例子中)?
  2. 另外問題。當你設置waitUntilDone = YES會發生什麼。我嘗試過,但我沒有看到任何區別。
+0

請重新格式化您的問題,以正確使用mini-Markdown,SO的格式化語法。 –

回答

0

1)makeMyProgressBarMoving是您的選擇器。 2)如果您嘗試在另一個線程中對主線程執行選擇器,則只能使用onMainThread版本。該文檔說:

等待:一個boolen,指定E當前線程阻塞直到指定的選擇器在主線程上的接收器上執行之後。

相關問題