在connectionDidFinishLoading:,NSURLConnection委托方法中发布后,无法收到通知

时间:2011-11-18 20:22:17

标签: objective-c ios nsurlconnection nsnotificationcenter

我无法收到通知:

用于执行NSURLConnection异步填充的类

- (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];

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

错误在这里:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];

这意味着通知中心会将名为name:kWebServiceURLTemperaturaMaximaKMLNotitificationName的通知发送到self,该通知也由self生成。您应该将object:self替换为object:nil(以接收任何名为name:kWebServiceURLTemperaturaMaximaKMLNotitificationName的通知)或实际发送通知的对象。