我正在尝试设置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>
编辑:看一下它,它看起来很像您的示例:Objective c : How to set time and progress of uiprogressview dynamically?
仔细检查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上。我将其移动了一点,以使其不再重叠。
我不确定为什么会这样。它本来应该可以在原始情况下工作,但这就是我解决的方法。
就我而言,需要宽度限制。