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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to