I am working on an IPhone application.
I am doing an asynchronous update from the server. When the update finishes downloading, I issue a NSNotification
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_DATA_RECEIVED object:self userInfo:@{ @"updateKey": updateKey }];
In my viewController I declared the observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateReceived:) name:NOTIFICATION_DATA_RECEIVED object:nil];
And the selector that will be performed when notification received:
- (void) updateReceived:(NSNotification *)notification
{
[self performSelectorOnMainThread:@selector(updateData:) withObject:nil waitUntilDone:NO];
}
updateData
need to be performed on the main thread because it changes the entities in the core data and it cannot be done on a different threat unless we use some specific libraries. I dont want to change that.
My problem:
updateData
is taking a while and it is freezing the UI since it is on the main thread. I need to display a "Loading Data..." Overlay while this is done.
I have 2 methods in the view controller that will display the overlay : showLoadingOverlay
and hideLoadingOverlay
I need to call showLoadingOverlay
when the updateData
is called and hideLoadingOverlay
when it is done.
The problem is that since it is peformed on the main thread I dont know how to make the overlay appear while updating the data. I tried to show it directly before sending the notification and hide it at the end of the updateData
method but it is not working.
Any help is greatly appreciated.
Thanks