I am trying to pass NSString from one class to another. Let's say I have ViewController A and ViewController B. I want to pass NSString from A to B.
In ViewController A, I have following code :
[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationMessageEvent" object:userType];
//Here user type is a string I get using delegate and I need to pass this userType to ViewController B
In ViewController B, I have following code : In viewDidLoad , I have following code :
[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(notificationAction:) name:@"NotificationMessageEvent" object:nil];
//This NSNotificationCenter method is called
I have registered the following selector method.
-(void) notificationAction:(NSNotification *) notification
{
if ([notification.object isKindOfClass:[NSString class]])
{
NSString *message = [notification object];
// do stuff here with your message data
NSLog(@"%@ is message",message);
}
else
{
NSLog(@"Error, object not recognised.");
}
}
//The above selector method is never called.
I have read other similar stackoverflow answers but I have not been able to find any solutions regarding this.