I have a method that pulls data from web service in XML. It is quite large data. So i am doing that is background thread like this
I post a notification.This is screen A.
In my other screen, screen B I listen for notification to act on it.
My question is since i am notifying on background thread how is it possible for the main thread to know about a notification. I want to tell main thread about the background thread finishing its work and then do what is described in the notification method. If you have questions, please ask. Thanks
Code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[self getAllCustomerValues];
});
- (void)getAllCustomerValues
{
....do work
//at the end of this method
NSNotification *notification =[NSNotification notificationWithName:@"reloadRequest"
object:self];
[[NSNotificationCenter defaultCenter] postNotification : notification];
}
In my other screen, screen B I listen for notification to act on it.
Code:
//Screen B
-(void)viewDidLoad
{
...some work
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stopActivityIndicator)
name:@"reloadRequest"
object:nil];
}
-(void)stopActivityIndicator
{
..do some work
}
Last edited by a moderator: