iOS Tips : NSNotification raised multiple times

If you add the notification observer in a method called multiple times, you will receive the notification multiple times too.

To avoid that , you’ve got 2 solutions :

  1. Try to either put the [[NSNotificationCenter defaultCenter] addObserver:...] in the init method instead,
  2. Put the [[NSNotificationCenter defaultCenter] addObserver:...] in the viewWillAppear method and call [[NSNotificationCenter defaultCenter] removeObserver:self] in the viewWillDisappear method.

Here is a link to Stackoverflow to explain that.

This entry was posted in app development, iOS, tutoriels. Bookmark the permalink.

2 Responses to iOS Tips : NSNotification raised multiple times

  1. Pingback: iOS Tips : NSNotification raised multiple times | Dans un an… | Dans un an...

  2. northern tools says:

    Have you ever thought about publishing an ebook or guest authoring
    on other blogs? I have a blog based on the same information you discuss
    and would really like to have you share some
    stories/information. I know my audience would enjoy your work.
    If you’re even remotely interested, feel free to send me an e-mail.

Comments are closed.