Search code examples
nsnotificationcenternsnotifications

NSNotificationCentre without date?


I want an NSNotification to be triggered when a non date based event occurs. Any ideas? Thanks!


Solution

  • You have to create an NSNotification and add this notification to the default notification centre. You can do this in that unique line :

    [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:object userInfo:dictionary];
    

    You then have to say to your project that when a notification is sent with the name notificationName, trigger this specific method on my code. And this is done with :

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationMethod) name:notificationName object:object];
    

    There is a full tutorial here.