1

我正在尝试设置 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 {

}

}
4

4 回答 4

2

尝试打电话[progressBar setProgress:<value> animated:YES];而不是progressBar.progress = <value>

编辑:看看这个,它看起来很像你的例子:Objective c : How to set time and progress of uiprogressview dynamic?

于 2013-01-04T10:23:28.860 回答
1

仔细检查 ProgressBar 在 Interface Builder 中是否正确链接。

如果它仍然不起作用,请尝试使用[progressBar setProgress:0];and [progressBar setProgress:actual+0.1];

也知道 UIProgressView 有一个[progressBar setProgress:<value> animated:YES];方法。可能看起来更干净。

于 2013-01-04T10:24:08.990 回答
1

它应该是这样的:

- (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];
}
于 2013-08-07T10:28:06.077 回答
0

今天早上我遇到了同样的问题。似乎progressBar 部分位于UITableView 之上。我移动了一点,使它不再重叠。

我不确定这是为什么。它应该在原来的情况下工作,但这就是我解决它的方法。

于 2014-12-09T15:18:12.720 回答