2011-09-28 113 views
3

大家好我使用進度條指示我的應用程序中xml解析的狀態,但它沒有顯示逐步更新,而是進度條正在加載之後整個XML解析結束了,直到那個時候它被卡住,並沒有顯示任何進度。如何解決這個問題。任何人都可以幫助我。 我用下面的代碼進度條沒有顯示iphone中的一步一步進展

IBOutlet UIProgressView * threadProgressView; 

threadProgressView.progress = 0.0; 
[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO]; 

- (void)makeMyProgressBarMoving 
{ 
    float actual = [threadProgressView progress]; 
    if (actual < 1) { 
     threadProgressView.progress = actual + ((float)1/(float)10); 
     [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO]; 
    } 
    else{ 
     /* something else */ 
    } 
} 
+0

你叫'[自performSelectorOnMainThread:@selector(makeMyProgressBarMoving)withObject:無waitUntilDone:NO];'在另一個線程? – Nekto

+0

你用來加載/讀取xml文件到內存中的代碼是什麼? –

回答

1
  1. 了第二的每1/10在主線程中創建一個定時器。讓它擊中你的「makeMyProgressBarMoving」功能。

    myTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:YES]; 
    

然後編輯功能,看起來像這樣:

- (void)makeMyProgressBarMoving { 

     float actual = [threadProgressView progress]; 
     if (actual < 1) { 
     threadProgressView.progress = actual + ((float)1/(float)10); 
     return; 
    } 

    //if you got here that means the progress view is greater than 1 so now you can kill your timer that you had running every 1/10th of a second. 

    [myTimer invalidate]; 

}