TruMan1
TruMan1

Reputation: 36078

Infinite step for progress view?

I need to provide a status on the screen for the user while an arbitrary process is happening. I have no way of knowing how long it will take. How can I increment the progressView forever (it will slow down as it approaches 1).

Upvotes: 0

Views: 1496

Answers (3)

Mtoklitz113
Mtoklitz113

Reputation: 3878

This will be your best friend if you're willing to replace the progress view! It's got everything you want.

Upvotes: 1

Jose Castellanos
Jose Castellanos

Reputation: 548

I think you need to post a little more about the arbitrary process but typically an infinite progress view would be a rotating circle or something of continuous motion that shows the user that its not frozen. You can include a label on the view that you can update with text of what is happening.

In order to do a calculation you need to have to have a total and current amount value. So for instance in a loop you could do something like this:

var objects = [Object]()
progressView.label.text = "starting"
progressView.startAnimating()
var i = 0
for object in objects {
  progressView.label.text = "processing \(i + 1) of \(objects.count)"
  doProcess(object)
  progressView.label.text = "processed \(i + 1) of \(objects.count)"
  i = i + 1
}
progressView.label.text = "done"

If you need to slow the animation just increase the animation duration instead of i

Upvotes: 0

user3179636
user3179636

Reputation: 569

One possible solution is to increment it half the distance to the end. So the first time the progressview is at 0, you take 1 minus how far it has gone (0) and divide that by 2. So (1-0)/2 = .5. The next time would be (1-.5)/2 = .25 so you would add .25 and get .75 This will work although probably is not the desirable solution as the first time it will go quite quickly and users will assume the task is halfway done when really the first part is done and the progress view will slow down considerably

Upvotes: 0

Related Questions