2012-04-12 84 views
4

我想增加進度條並在標籤上顯示百分比。但是,當「incrementaProgres」函數被調用時,兩者都保持不變。 IBOutletsxib上正確鏈接,並且還測試了當函數被調用時變量具有適當的值。感謝Xcode UIProgressBar不會增加

從委託:

loadingViewController *theInstanceP = [[loadingViewController alloc] init]; 
[theInstanceP performSelectorOnMainThread:@selector(incrementaProgres:) withObject:[NSNumber numberWithFloat:0.15] waitUntilDone:YES]; 

loadingView類:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [spinner startAnimating]; 
    [progress setProgress:0.0]; 
} 

- (void)incrementaProgres: (CGFloat)increment{ 

    [progress setProgress:(progresInc + increment)]; 
    carrega.text = [NSString stringWithFormat: @"%f", (progresInc + increment)]; 

} 

回答

4

進度條的progress0.01.0之間,你的代碼將它的15.0增量,這是超出範圍。你的增量應該是0.15,而不是15.0

+0

謝謝,android讓我忘記了iOS pb的基礎知識:)但是,仍然沒有刷新,雖然vars有適當的價值... – Jaume 2012-04-12 10:36:21

+1

@Jaume是'carrega.text'被設置爲0和1之間的正確值? – dasblinkenlight 2012-04-12 10:40:26

+0

carrega標籤不變,設置爲指定值,但未在視圖上更新 – Jaume 2012-04-12 10:53:53

2

進展是在0.0和1.0之間的值。

編輯: 您是否嘗試撥打[myView setNeedsDisplay];

2日編輯:

也許有一個困惑:viewDidLoad叫你提出的觀點的權利之前。因此,在此處顯示的代碼中incrementaProgres:viewDidLoad之前被調用。

+0

謝謝,編輯但同樣的問題......似乎填寫var值正確,但不刷新... – Jaume 2012-04-12 10:37:48

+0

編輯我的答案。 – dasdom 2012-04-12 10:40:01

+0

你的意思是像[progress performSelectorOnMainThread:@selector(setNeedsDisplay)withObject:nil waitUntilDone:YES]; ?添加但同樣的問題... – Jaume 2012-04-12 10:52:51