Donc, je ne fais que tester NSNotifications sur une variété de cas et celui-ci est déroutant. J'apprécierais que vous puissiez m'aider à comprendre NSNotifications!Les contrôleurs de vue ne reçoivent parfois pas de NSNotification
J'ai un contrôleur de navigation.
J'ai un UIBarButtonItem appelé "Ajouter", qui affiche une notification DidAddNotification
Si je clique sur Ajouter cela me pousse à View2.
// I add view2 as observer and write method for this and NSlog if it gets implemented //
Je nouveau me pousse à voir 3.
// I add view3 as another observer and use the same method as the previous view and I NSlog if it gets implemented//
De 3 Voir, je popToRootViewControllerAnimated: OUI et je reviens à 1. et à nouveau suivre la même procédure.
Voilà donc comment le contrôle est ...
1 -> 2 -> 3 -> 1
if I press add again,
the control is again the same 1 -> 2-> 3-> 1
est ici la sortie (NSLogs):
J'appuyez sur Ajouter pour la première fois:
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.
I appuyez de nouveau sur Ajouter:
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.
J'appuyez sur Ajouter une fois de plus:
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..
Quelqu'un pourrait-il me dire pourquoi
- NSLog ne sont pas imprimées en vue 3 pour la première fois, mais imprime tout autre moment?
- Pourquoi NSLog imprime-t-il dans la vue 2 pour la première fois et ne l'imprime plus jamais?
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
s'il vous plaît code postal, votre question est trop longue et difficile à comprendre. –
S'il vous plaît dites-moi quelle partie est difficile à comprendre, et je ferai de mon mieux pour l'éditer et le poster. – Legolas
C'est bizarre que seules certaines notifications se déclenchent. Comment installez-vous les observateurs? – justin