NSNotification does not reach all observers

I use NSNotificationfor a specific set of events. I have three views such that I have the “ADD” button in view 1 and a click, which makes me move from view 1 to view 2, to view 3 and return to view 1 again.

1-> 2-> 3-> 1

I use NSNotificationto press the view controller if the ADD button on view 1 is pressed, and I update other views accordingly based on the notification sent by View 1.

When a notification is sent from view 1, only view 2 receives it. View 3 is not.

How is this possible? The code for observers is EXACTLY the same in view 2 and view 3.

This is the code to add observers to view 2 and view 3:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(didPressAdd:) 
                                             name:@"DidAddNotification" 
                                           object:nil];

I also delete them in the function dealloc()correctly.

+3
source share
2 answers

Going back to 1 using the navigation controller will delete 2 and 3. Thus, in dealloc add a log that says that the particular controller has stopped listening. You will see that the listener is freed, after which he will not listen to notifications. Updated sampleto send a return notification.

+3
source

viewDidLoad viewWillAppear: . initWithNibName:bundle: ( xib ) - init, (initWithCoder: ), , - . , .

+1

All Articles