NSNotification not being sent when postNotificationName: called

后端 未结 7 885
生来不讨喜
生来不讨喜 2020-12-29 08:17

I\'m trying to get one instance of using NSNotificationCenter with addObserver and postNotificationName but I can\'t work out why it w

7条回答
  •  清歌不尽
    2020-12-29 08:53

    Have you tried any other names but @"Event" and nil? Just to be sure, you could define your event names in one file and include that into both notification registration and sending. For example:

    Header file:

    extern NSString * const NOTE_myEventName;
    

    Source file:

    NSString * const NOTE_myEventName = @"MyEventName";
    

    Registration:

    [[NSNotificationCenter defaultCenter]
     addObserver:self
        selector:@selector(handleMyEvent:)
            name:NOTE_myEventName
          object:nil];
    

    Notification sending:

    [[NSNotificationCenter defaultCenter]
        postNotificationName:NOTE_myEventName object:nil];
    

提交回复
热议问题