I implemented NSNotificationCenter in my application. I send a notification when image decoding is performed. The first time decoding an image will be performed 8 times. So the notification should be sent 8 times. But it calls 64 times (8 * 8).
Here is my code as I implemented → // Initialization
- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getHRImage:) name:@"DecodeComplete" object:nil];}
// call method
-(void)getHRImage:(NSNotification *) notification { if ([[notification name] isEqualToString:@"DecodeComplete"]) NSLog (@"Successfully received the DecodeComplete notification! "); }`
// release
- (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"DecodeComplete" object:self];
// Email Notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"DecodeComplete" object:self];
Someone can tell me where I was wrong.
Thanks in advance.
// The call method is similar (call 8 times)
-(void)decode { NSLog(@"---------- Decoding is Complete ---------"); [[NSNotificationCenter defaultCenter] postNotificationName:@"MdjDecodeComplete" object:self]; }
ios objective-c iphone nsnotificationcenter nsnotification
Kiran kumar
source share