I have a simple app that processes some text from a website in a for … next loop. I have added an iOSProgressBar which is supposed to update as each line is processed but it just sits at zero until everything is done and then goes to 100%. Same if I try to use a label or textarea, I don’t get a count, just the final number. On a Mac I would solve this by forcing the ProgressBar to refresh but I have no idea how to make the display refresh in iOS. Any help very welcome. Cheers, Richard
Doing things in a loop like that blocks the OS from updating the UI until the work is done
Hence why you see it behaves this way
And, should this take too long, your app could be killed by the OS for hogging the CPU
iOS is VERY sensitive to apps hogging the CPU since that can interfere with the phone & other functions
The best thing you could do is use a thread to process the file and use a timer to update the UI from its action
This technique has been discussed a lot esp as it relates to NTOT updating the UI from a thread
Thanks Norman, I’ve done something similar for a Mac application so I’ll have a go. I understand the pressure on CPU but I can’t help thinking this seems a complex way to do something very simple. Cheers.
It is not so complex, really. Just move all the code you had before to the Run event of a thread, and simply update a View or Module property, such as ProgressBarValue. Then the timer picks that property and applies it to the progressbar at regular intervals.
In iOS, if you think about it, it is not so much a question of processor use, as phone use. Nothing must prevent the normal use of the phone, which is to be able to talk, pick up a call, call, ring, and so on. A tight loop could jeopardize all these functions. The primary function of an iPhone is not computing, it is phoning.