![](/img/trans.png)
[英]Calling progressTintColor does not update UIProgressview progress between 0.01 and 0.05
[英]Why does UIProgressView not update?
我正在嘗試設置 UIProgressView 的進度,但 progressView 不會“更新”。 為什么? 你知道我做錯了什么嗎?
這是我在 ViewController.h 中的代碼:
IBOutlet UIProgressView *progressBar;
這是 ViewController.m 中的代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
progressBar.progress = 0.0;
[self performSelectorOnMainThread:@selector(progressUpdate) withObject:nil waitUntilDone:NO];
}
-(void)progressUpdate {
float actual = [progressBar progress];
if (actual < 1) {
progressBar.progress = actual + 0.1;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self `selector:@selector(progressUpdate) userInfo:nil repeats:NO];`
}
else {
}
}
嘗試調用[progressBar setProgress:<value> animated:YES];
而不是progressBar.progress = <value>
編輯:看看這個,它看起來很像你的例子: 目標c:如何動態設置uiprogressview的時間和進度?
仔細檢查progressBar 是否在Interface Builder 中正確鏈接。
如果還是不行,嘗試使用[progressBar setProgress:0];
和[progressBar setProgress:actual+0.1];
.
也知道 UIProgressView 有一個[progressBar setProgress:<value> animated:YES];
方法。 可能看起來更干凈。
它應該是這樣的:
- (void)viewDidLoad
{
[super viewDidLoad];
progressBar.progress = 0.0;
[self performSelectorInBackground:@selector(progressUpdate) withObject:nil];
}
-(void)progressUpdate {
for(int i = 0; i<100; i++){
[self performSelectorOnMainThread:@selector(setProgress:) withObject:[NSNumber numberWithFloat:(1/(float)i)] waitUntilDone:YES];
}
}
- (void)setProgress:(NSNumber *)number
{
[progressBar setProgress:number.floatValue animated:YES];
}
今天早上我遇到了同樣的問題。 似乎進度條部分位於 UITableView 之上。 我稍微移動了它,使其不再重疊。
我不確定這是為什么。 它應該在原始案例中有效,但我就是這樣解決的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.