Note that there are some explanatory texts on larger screens.

plurals
  1. POView controllers sometimes do not receive an NSNotification
    primarykey
    data
    text
    <p>So, I am just testing NSNotifications on a variety of cases and this one is confusing. I would appreciate it if you could help me understand NSNotifications !</p> <p>I have a Navigation Controller. </p> <p>I have a UIBarButtonItem called "Add", which posts notification DidAddNotification</p> <p>If I click Add it pushes me to view2. </p> <pre><code> // I add view2 as observer and write method for this and NSlog if it gets implemented // </code></pre> <p>I again push myself to view 3. </p> <pre><code>// I add view3 as another observer and use the same method as the previous view and I NSlog if it gets implemented// </code></pre> <p>From View 3, I popToRootViewControllerAnimated:YES and I get back to 1. and again follow the same procedure.</p> <p>So this is how the control is ...</p> <pre><code>1 -&gt; 2 -&gt; 3 -&gt; 1 if I press add again, the control is again the same 1 -&gt; 2-&gt; 3-&gt; 1 </code></pre> <p><strong>Here's the output (NSLogs)</strong> :</p> <p>I press Add for the first time:</p> <pre><code>2011-06-09 14:47:41.912 Tab[5124:207] I am the notification in view2 2011-06-09 14:47:41.912 Tab[5124:207] I pressed Add Button and I just sent a notification from view 1 // No notification in view 3 ?? // I am now back to view 1. </code></pre> <p>I press Add again: </p> <pre><code>2011-06-09 14:47:51.950 Tab[5124:207] I am the notification in view3 2011-06-09 14:47:51.951 Tab[5124:207] I pressed Add Button and I just sent a notification from view 1 // No Notification in view 2 ??? // ... I am now back to view 1. </code></pre> <p>I press Add one more time:</p> <pre><code>2011-06-09 14:47:59.160 Tab[5124:207] I am the notification in view 3 2011-06-09 14:47:59.161 Tab[5124:207] I pressed Add Button and I just sent a notification from view 1 // No Notification in view 2 ??? // ... I am now back to view 1. And this goes on.. </code></pre> <p>Could anyone tell me why </p> <ol> <li>NSLog did not print in view 3 for the first time but prints all other time?</li> <li>Why NSLog prints in view 2 for the first time and never prints it again ?</li> </ol> <p>Code:</p> <pre><code>[[NSNotificationCenter defaultCenter] postNotificationName:@"DidAddNotification" object:self]; // I put this in the - (IBAction) for addData - (void)didPressAdd:(NSNotification *)notification { //NSLogs// } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didPressAdd:) name:@"DidAddNotification" object:nil]; // I put this in the viewDidLoad of view 1 and view 2 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload