NSNotification not sent/received?

Up vote 1 down vote favorite share g+ share fb share tw.

I've been trying to figure this out for a whole day now and I'm starting to become desperate... So here is my problem: I have a table view controller showing a list of files. The user can download new files to this list. I handle the downloads asynchronously in a separate class.

When a new file has been downloaded I want to notify the table view controller, so it can update the list. The delegate pattern doesn't really fit here, because multiple instances have to be notified, so I want to use NSNotificationCenter. In the view controller's viewDidAppear: method I register as an observer: NSNotificationCenter defaultCenter addObserver:self selector:@selector(downloadComplete:) name:kDownloadCompleteNotification object:nil; This is called definitely before posting the notification, because the user has to tap the add button on the view controller to start a new download.

When the download is done I post the notification (in the DownloadManager class): NSNotificationCenter defaultCenter postNotificationName:kDownloadCompleteNotification object:self; However, my notification handler method in the view controller is never called. I added breakpoints and it's just not called. I also tried to set the object to nil.

No difference. - (void)downloadComplete:(NSNotification *)notification { NSLog(@"Inserting new files into table view. "); } Both, registering and posting the notification is done on the main thread (I don't think that matters anyway).

The view controller is not released or anything. I didn't make any typo as far as I can tell. The name strings are the same constant.

If set the name argument to nil when registering as an observer, I receive all kind of (system) notifications, but not my own ones. However if I post a test notification right after registering (in viewDidAppear) it works. I don't know what else I should check... Any hint is very appreciated.

Thanks! Ios xcode cocoa-touch foundation nsnotification link|improve this question edited Dec 7 '11 at 21:31Rob Keniger18.7k12240 asked Dec 7 '11 at 21:23DrummerB162.

It very much sounds like one of your objects is being deallocated. – Rob Keniger Dec 7 '11 at 21:30 1 You've logged the registration and post to prove they happen in the correct order? Also log any time you remove an observer.

– Firoze Lafeer Dec 7 '11 at 21:37 What a big oversight of me... I remove the observer in viewDidDisappear, because I only need to update the list in the visible view controller. However at the time when the notification is sent, the download view controller is actually on top of my file list view controller. – DrummerB Dec 7 '11 at 21:45 For me it seems like your notification isn't fired at all (you've said, that you've posted a test notification and it's ok).

Try to set breakpoint just before notification post part of the code. If you're download asynchronically, check that you got callbacks at download finish. (Connection delegate, I guess) – Ariel Dec 7 '11 at 22:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions