tags:

views:

18

answers:

1

i am a new programmer .... i am looking at a project which was provided me by my org. for study... the problem is that in this project i found some codes which i never saw before please tell me why the following code is written there

-(void)notifications { [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(hideViews) name: @"Hide" object:nil]; }

this problem was arised because this project has only coding even for designing.....

sorry if this is a silly question... and for my bad english also

+1  A: 

You should read up on how notifications work in Cocoa. Consult Apple's documentation for more information: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html

Basically, NSNotificationCenter is a class that broadcasts NSNotifications from one object to potentially many observing objects. One object can post a notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationName" object:self];

and other objects can listen for this notification.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler:) object:theObjectThatPostedTheNotification];

Then, when the first object posts the notification, NSNotificationCenter will notify the other observing object, and notificationHandler: gets called.

anshuchimala