I apologize if my terminology isn’t correct – I’ve been learning Objective C for just a few days, so I’m still a little unfamiliar.
I have a ViewController that has a progress bar (UIProgressView) hooked up with an IBOutlet using Xcode’s storyboard “quick drag” functionality. The ViewController instantiates an object of a custom class I have written. It passes a message to a selector of that object that does a lengthy bit of work which takes about 15-20 seconds. I want to be able to update the progress bar as the job progresses, but I can’t work out how to access the calling class’s UIProgressView to do this. I don’t need to use a timer, as the object’s method runs a long loop which I know the limits of, and can update the progress bar based on current position in the loop.
I’m sure it’s a pretty fundamental concept in objective C programming, but a prod towards the right direction or documentation would really help me out.
Use the delegate pattern.
Create a protocol for your ProgressBar updates:
Your ViewController implements the delegate and contains this onUpdateProgress method.
Your custom class has a delegate variable which you set in its initializer, its set to the ViewController instance.
Update your CustomClass designated initializer to pass delegate:(id)delegate as a parameter.
When initializing your CustomClass, [[CustomClass alloc] initWithDelegate:self];
OR make delegate a settable @property, and update via [mCustomClass setDelegate:self];
Then you can call the onUpdateProgress method from your custom class.