Best way to update UI when dealing with data synchronization
- by developerdoug
I'm working on a bug at work. The app is written in Objective-C for iOS based device, for the iPad. I'm the new guy there and I've been given a hard task. Sometimes, the UIButton text property does not show the correct state when syncing. Basically, when the app is syncing, my UI control would say "Syncing" and when its not syncing it'll display "Updated @ [specific date]". Right now there is a property on the app delegate called "SyncInProgress". When querying / syncing, occurring on background thread, it updates a counter. The property will return a bool checking expression 'counter 0'.
There are three states I need to deal with.
Sync has started.
Sync is updating tables.
Sync finished.
These items need to occur in order.
My coworker suggested to take a state based approach instead of just responding to events. I'm not sure about how to go about that.
Would it be best to have the UI receive a notification to determine what state its in or to pull every so often if state changed?
Here are two posts that I put on stackoverflow, in the last few days, that relate to this.
http://stackoverflow.com/questions/11025469/ios-syncing-using-a-state-approach-instead-of-just-reacting-to-events
http://stackoverflow.com/questions/11037930/viewcontroller-when-viewwillappear-called-does-not-always-correctly-reflect-stat
Any ideas that anyone might have to very much appreciated.
Thanks,
developerDoug