UIProgressView progress not updating in iOS8&9 but work in iOS7 even when run in the main thread. My code is the following, hope have a help.
- (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];
}
@property (strong, nonatomic) UIProgressView *progressView;
@property (nonatomic) CGFloat usedTime;
i put it in viewDidLoad
Method
_progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 500, self.view.bounds.size.width, 50)];
[self.progressView setProgress:0.0];
[self.view addSubview:self.progressView];
self.timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target:self selector: @selector(handleProgressBar) userInfo: nil repeats: YES];
[![enter image description here][1]][1]//-----------------------------------------------------------------------
- (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.progressView setProgressTintColor:[UIColor redColor]];}
}
}
//-----------------------------------------------------------------------
- (void)updateProgress:(NSNumber *)progress {
float fprogress = [progress floatValue];
//self.progressBar.progress = fprogress;
[self.progressView setProgress:fprogress animated:YES];
}
//-----------------------------------------------------------------------