Hi All,
I am struggling to find a way to synchronize operation on IPhone app. I have three main NSOperation.
NSInvocationOperation *showSpinner = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(spinnerOn:) object:YES];
NSInvocationOperation *reloadDatasource = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(reloadDatasource) object:nil];
NSInvocationOperation *hideSpinner = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(spinnerOn:) object:NO];
// Add dependency
[reloadDatasource addDependency:showSpinner];
[hideSpinner addDependency:reloadDatasource];
[self.queue addOperation:showSpinner];
[self.queue addOperation:reloadDatasource];
[self.queue addOperation:hideSpinner];
I can see that the three operations are correctly started in sequence. However, as you can imagine, the first operation create a UIView and attach it on top, while the last one should remove it.
It happens that graphically speaking the operations happens at once on the screen. So I can see the table already loaded, while the spinner is on screen, or other strange unsynchronized things.
I understood that change on the graphic side happen on the main thread. So I am asking how can I modify the code to do what it is supposed to do. Which is: create spinner, load data, and remove spinner ? Is there a common way to separate graphic operation and data operation ? For example create two distinct operation.
thanks