在 connectionDidFinishLoading:, NSURLConnection 委托方法中发布后无法收到通知 [英] can't receive a notification after posting inside connectionDidFinishLoading:, NSURLConnection delegate method
问题描述
我无法收到通知:
一个用于做 NSURLConnection 异步操作的类
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];
}
另一个观察通知的类:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];
有什么想法吗?
推荐答案
错误在这里:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];
这意味着通知中心会将名为name:kWebServiceURLTemperaturaMaximaKMLNotitificationName
的通知发送给同样由self
生成的self
.您应该将 object:self
替换为 object:nil
(接收任何名为 name:kWebServiceURLTemperaturaMaximaKMLNotitificationName
的通知)或实际发送通知的对象.
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.
这篇关于在 connectionDidFinishLoading:, NSURLConnection 委托方法中发布后无法收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!