How to call a function using NSNotification on custom Event in Xcode or Objective C ?


Step 1. In viewDidLoad   // add notification

– (void)viewDidLoad
{
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MoveToNextView:) name:@”SomeNotificationName” object:nil];
    // Do any additional setup after loading the view, typically from a nib.
}

Step 2:  call Notification function

-(IBAction)SendMessege:(id)sender{
      [[NSNotificationCenter defaultCenter] postNotificationName:@”SomeNotificationName” object:nil];
}

step 3.

-(IBAction)MoveToNextView:(id)sender{
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@”Alert” message:@”Notification Alert” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”ok”, nil];
    [alert show];
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s