问题
I can't receive a notification with this:
a class for doing NSURLConnection async stuff
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:_receivedData, @"receivedData", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self userInfo:userInfo];
}
another class observing the notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];
any thoughts?
回答1:
Error is here:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];
This means that notification center will send notification named name:kWebServiceURLTemperaturaMaximaKMLNotitificationName
to self
that is also generated by self
. You should replace object:self
with object:nil
(to receive any notification named name:kWebServiceURLTemperaturaMaximaKMLNotitificationName
) or with object that is actually sending the notification.
来源:https://stackoverflow.com/questions/8188633/cant-receive-a-notification-after-posting-inside-connectiondidfinishloading-n