Friday, June 27, 2014

IPhone: message passing between different views using notifications

In the sender view

[[NSNotificationCenter defaultCenter] postNotificationName:@"Mynotification" object:nil];



In the receiver view
(In view did load)

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(functionToRespondMyNotification) name:@"Mynotification" object:nil];



#pragma mark custom notification responders

-(void) functionToRespondMyNotification
{
    // response
}

In viewdiddisappear

 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Mynotification" object:nil];

No comments:

Post a Comment