• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
postNotificationName Executes Many Times for a Single Invocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

postNotificationName Executes Many Times for a Single Invocation


  • Subject: postNotificationName Executes Many Times for a Single Invocation
  • From: Bing Li <email@hidden>
  • Date: Mon, 06 Jun 2011 21:40:29 +0800

Dear all,

I got a problem which confused me when using postNotificationName. The
method that invokes "postNotificationName" is as follows. The line that
includes "postNotificationName" runs multiple times even though the method
is invoked only one time. Why could it happen?

-(void)notifyMessageReceived:(NSString *)message
{
        // The line is added to prove that the method is invoked.
        NSLog(@"****** Begin NotifyMessageReceived");

        NSMutableDictionary *messageDictionary = [[[NSMutableDictionary
alloc] initWithCapacity:5] autorelease];
        [messageDictionary setObject:message forKey:@"RECEIVED_MESSAGE"];

        // The following line can execute many times even though the method
is invoked for only once! When will it happen?
        [[NSNotificationCenter defaultCenter]
postNotificationName:@"MESSAGE_RECEIVED"
object:self userInfo:messageDictionary];

        // The line ensures that the method is ended
        NSLog(@"****** End NotifyMessageReceived");
}

The log is shown as follows similarly. This log tells a single invocation
got three notifications. Why?

2011-06-06 21:38:48.281 Overlay[4515:3507] ****** Begin
NotifyMessageReceived
2011-06-06 21:38:48.282 Overlay[4515:3507] Message Received!
2011-06-06 21:38:48.282 Overlay[4515:3507] Message Received!
2011-06-06 21:38:48.282 Overlay[4515:3507] Message Received!
2011-06-06 21:38:48.283 Overlay[4515:3507] ****** End NotifyMessageReceived

Thanks so much!

Best regards,
Bing
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: postNotificationName Executes Many Times for a Single Invocation
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Can NSNotificationCenter Memorize Old Events?
  • Next by Date: Re: postNotificationName Executes Many Times for a Single Invocation
  • Previous by thread: Re: Can NSNotificationCenter Memorize Old Events?
  • Next by thread: Re: postNotificationName Executes Many Times for a Single Invocation
  • Index(es):
    • Date
    • Thread