Reputation: 11284
I am trying to utilize the NSNotificationCenter and for some reason the selector method is never called.
- (NewsItem *) loadNewsItemDetail:(NewsItem *)currentNewsItem
{
self.newsItem = currentNewsItem;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DownloadNewsItem) name:@"connectionDidFinishLoadingComplete" object:nil];
return self.newsItem;
}
- (void) DownloadNewsItem:(NSNotification *) notification
{
NSString *urlString = [Configuration newsStreamAPIURL:plNewsAPIKey];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
...
[[NSNotificationCenter defaultCenter] postNotificationName:@"connectionDidFinishLoadingComplete" object:nil];
}
Any reason why my DownloadNewsItem would never be called based on what I have provided?
Thanks!
Upvotes: 0
Views: 731
Reputation: 354
You need a colon in your selector method, because it takes a parameter (an NSNotification
in this case).
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DownloadNewsItem:) name:@"connectionDidFinishLoadingComplete" object:nil];
Upvotes: 4
Reputation: 29767
You have forgotten :
symbol after DownloadNewsItem
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(DownloadNewsItem:)
name:@"connectionDidFinishLoadingComplete"
object:nil];
Upvotes: 1