0

I am despreate with this ProgressBar-issue.

The below code shall test a ProgressBar-update.

But the View only shows a frozen bar with progress = 0

What is wrong here ???

What is necessary (else than dispatching on the main-queue) for a UIProgressView to work ?

Here is my code:

import UIKit

class TestViewController: UIViewController {

    @IBOutlet weak var progressBarOutlet: UIProgressView!

    override func viewDidLoad() {
        super.viewDidLoad()

        DispatchQueue.main.async {
            // self.progressBarOutlet = UIProgressView()
            self.progressBarOutlet.isHidden = false
            var i = 0
            while i < 10 {
                i = i + 1
                self.progressBarOutlet.setProgress(Float(Float(i) * Float(0.1)), animated: true)
                self.progressBarOutlet.progress = Float(Float(i) * Float(0.1))
                sleep(1)
            }
        }
    }
}
iKK
  • 6,394
  • 10
  • 58
  • 131

1 Answers1

0

You can tweak your calculation on setting the progress. It is always better to use

setProgress: animated:

I altered bit of your code and seems to be working.

Code Snippet:

        DispatchQueue.main.async {
              var i = 0
              while i < 10 {
                   self.progressBarOutlet.setProgress(Float(i), animated: true)
                  i += 1
              }
        }
  • Thanks, I had both, `.progress` and `.setProgress`, in the original code! Why does the pr-bar not move any more once I press the Back-button in the Detail-VC (where the pr-Bar is located) and re-enter the Detail-VC ? My main issue is that the pr-Bar does not move after RE-ENTERING the Detail-VC (having pressed the Back-Button of the Nav-Controler in the first place. After the Back-Button Pressing, there is no pr-Bar movement ! - (no matter of `.progress` or `.setProgress`). Refer to [here!](https://stackoverflow.com/questions/49059624/progress-bar-freeze-after-navigationcontroller-back-action) – iKK Mar 02 '18 at 07:19
  • You got your code in viewDidLoad. So once you are clicking on back button, ideally it will not call the viewDidLoad. If you want to make it all the time when user sees the view, then you should make the functionality in viewWillAppear. – thoughtbreaker Mar 02 '18 at 08:15
  • I was thinking of that - but then I see that a re-entering of the Detail-VC does call viewDidLoad. But I have a closer look at that again - maybe I missed something in the startup-behaviour of my Detail-VC... – iKK Mar 02 '18 at 08:35
  • Did not help ! (viewDidLoad or viewWillAppear - same thing: After Re-entering the Detail-VC there is no progressBar or UILabel Update whatsoever, .... before the re-enter everything fine - after only print()-statement works - but no screenupdate !!!! Why ????? – iKK Mar 02 '18 at 08:48