xcode 为什么 UIProgressView 不更新?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14155042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does UIProgressView not update?
提问by user1940136
I'm trying to set the progress of a UIProgressView, but the progressView doesn't "update". Why? Do you know what I am doing wrong?
我正在尝试设置 UIProgressView 的进度,但 progressView 不会“更新”。为什么?你知道我做错了什么吗?
Here is my code in ViewController.h:
这是我在 ViewController.h 中的代码:
IBOutlet UIProgressView *progressBar;
That's the code in ViewController.m:
这是 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 {
}
}
回答by OlavJ
Try calling [progressBar setProgress:<value> animated:YES];
instead of progressBar.progress = <value>
尝试调用[progressBar setProgress:<value> animated:YES];
而不是progressBar.progress = <value>
EDIT: Take a look at this, which looks a lot like your example: Objective c : How to set time and progress of uiprogressview dynamically?
编辑:看看这个,它看起来很像你的例子:目标 c:如何动态设置 uiprogressview 的时间和进度?
回答by Zachary Christopoulos
Double check that progressBar is linked correctly in Interface Builder.
仔细检查progressBar 是否在Interface Builder 中正确链接。
If it still doesn't work, try using [progressBar setProgress:0];
and [progressBar setProgress:actual+0.1];
.
如果它仍然不起作用,请尝试使用[progressBar setProgress:0];
和[progressBar setProgress:actual+0.1];
。
Also know that the UIProgressView has a [progressBar setProgress:<value> animated:YES];
method. May look cleaner.
也知道 UIProgressView 有一个[progressBar setProgress:<value> animated:YES];
方法。可能看起来更干净。
回答by HugoMasterPL
Its should look like this:
它应该是这样的:
- (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];
}
回答by Vincent
I had the same problem this morning. It appeared that the progressBar was partly over a UITableView. I moved it a little, so that it was not overlapping anymore.
今天早上我遇到了同样的问题。似乎进度条部分位于 UITableView 之上。我稍微移动了它,使其不再重叠。
I'm not sure why this is. It should have been working in the original case, but that is how I solved it.
我不确定这是为什么。它应该在原始案例中有效,但我就是这样解决的。