I have a UIProgressView which runs for 2.5 seconds however sometimes, like if the app is being resumed from multitasking, the loading bar will start halfway up. How would I reset the UIProgressView to 0.0 each time it is opened? I could set to 0 in the viewDidLoad
and then start the timer and animate it in the viewDidAppear
. I just need to know how I can set my progressView
to 0.
Asked
Active
Viewed 3,147 times
0

Brian
- 14,610
- 7
- 35
- 43

dwinnbrown
- 3,789
- 9
- 35
- 60
-
1Can you give an example of which actions would update the UIProgressView? Also i'd recommend setting it on the `viewWillAppear:` – Erakk Jul 16 '15 at 15:44
1 Answers
1
You set it on the viewWillAppear
, thats what it calls when the view will be displayed whether when you push it into the hierarchy ro when you resume from the background.
override func viewWillAppear() {
super viewWillAppear();
self.progressView.progress = 0.f;
}
You can also use the UIApplicationDidBecomeActiveNotification
.
//inside init
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateProgressBar", name: UIDeviceBatteryLevelDidChangeNotification, object: nil);
//on dealloc
NSNotificationCenter.defaultCenter().removeObserver(self);
//the update method
func updateProgressBar() {
self.progressBar.progress = 0.f;
}

Erakk
- 922
- 5
- 13
-
-
-
1all I did was use the code: `self.progressView.progress = 0.0;` as the bar itself is animated in a function outside the `viewDidLoad` – dwinnbrown Jul 16 '15 at 17:06