Reputation: 9293
I have a global function that downloads JSON data from a server and parses it. It normally takes about 5 seconds to run, so we do this in the background and then send out a notification, kNotificationDownloadSuccessful
.
One of the several observers of the notification is a MapView, who re-draws annotations based on the data it received. This, obviously, has to happen after it's told the data is ready by receiving kNotificationDownloadSuccessful
.
In some cases I want to re-center the map on the new data. This, obviously, cannot happen until the map has completed drawing annotations. So I implemented a second notification, kNotificationMapLocationSet
, which the callers fire if they want this to occur, and the map listens for it.
Now the problem... kNotificationMapLocationSet
is being received before kNotificationDownloadSuccessful
, which makes perfect sense really. The Map can't simply re-post it, or just call it's local re-center method, because it doesn't know if the recenter is required.
I thought about having the kNotificationMapLocationSet
set a flag in the Map, and then have the handler on kNotificationDownloadSuccessful
look at it and recenter if desired. But then that would fail in the case where the messages are received in their current order.
So is there a way to order the notifications? IE, delay this one until that one fires?
Upvotes: 0
Views: 119
Reputation: 1194
I believe you can use addObserver to check when the NSNotification is done. Let me know if this works:
NotificationCenter defaultCenter] addObserver:self
selector:@selector(callNextNotification:) name:@"notificationSent" object:nil];
It looks like you subclassed NSNotification, but this should still work.
Upvotes: -1