iOS - UIProgressView only updating once

本小妞迷上赌 提交于 2019-12-06 01:44:54

When you are dealing with User Interface (UI) components, you must perform the methods in the main thread. As a rule when you program, you need to set UI operations in the main thread, and heavy, complex and more performance demanding operations in background threads - this is called multithreading (as a side suggestion, would be good to read about GCD - Grand Central Dispatch. If you need to do longer operations, check this good tutorial from Ray Wenderlich.)

To solve this, you should call [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil]; and then, in the method, the following:

-(void)updateProgress {
    float currentProgress = myProgressBar.progress;
    NSLog(@"%0.2f", currentProgress);
    dispatch_async(dispatch_get_main_queue(), ^{
    [loadingProg setProgress:currentProgress+0.1 animated:YES];
    });
}

UI refreshes need to happen on the main thread. Change

[self performSelectorInBackground:@selector(updateProgress) withObject:nil];

to

[self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!