即使在主线程中运行,UIProgressView进度也不会更新

时间:2016-04-27 04:08:27

标签: ios objective-c iphone uiprogressview

UIProgressView进度在iOS8和9中没有更新,但即使在主线程中运行,也可以在iOS7中运行。我的代码如下,希望有所帮助。

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target:self selector: @selector(handleProgressBar) userInfo: nil repeats: YES];
}

- (void) handleProgressBar{
    if(self.usedTime >= 300.0)
    {
        [self.timer invalidate];
        self.timer=nil;
        [self submitAns:[NSNumber numberWithInt:-1]];
    }
    else
    {
        self.usedTime += 1;
        CGFloat progress = self.usedTime*(0.0033333333);

        [self performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:progress] waitUntilDone:NO];
        if(self.usedTime>200){
            [self.progressBar setProgressTintColor:[UIColor redColor]];}
    }
}

- (void)updateProgress:(NSNumber *)progress {
    float fprogress = [progress floatValue];
    //self.progressBar.progress = fprogress;
    [self.progressBar setProgress:fprogress animated:YES];
}

1 个答案:

答案 0 :(得分:0)

   
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
      integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<table class="table table-bordered">
  <tbody>
    <tr>
        <td>Collection 1</td>
        <td>5</td>
    </tr>
    <tr>
        <td>Collection 2</td>
        <td>5</td>
    </tr>
    <tr>
        <td colspan="2" class="no-line">-----------</td>
    </tr>
    <tr>
        <td>Total </td>
        <td>10</td>
    </tr>
  </tbody>
</table>

我把它放在@property (strong, nonatomic) UIProgressView *progressView; @property (nonatomic) CGFloat usedTime; 方法

viewDidLoad

Working For ME