I need to pass a NSMutableDictionary
from one class (ViewControllerA
) to another (ViewControllerB
) using NSNotificationCenter
. I have tried the following code but it doesn't work. I actually pass to the ViewControllerB
but the -receiveData
method isn't called. Any suggestion? Thanks!
ViewControllerA.m
- (IBAction)nextView:(id)sender {
[[NSNotificationCenter defaultCenter]
postNotificationName:@"PassData"
object:nil
userInfo:myMutableDictionary];
UIViewController *viewController =
[[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:NULL] instantiateViewControllerWithIdentifier:@"viewcontrollerb"];
[self presentViewController:viewController animated:YES completion:nil];
}
ViewControllerB.m
- (void)receiveData:(NSNotification *)notification {
NSLog(@"Data received: %@", [notification userInfo]);
}
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(receiveData:)
name:@"PassData"
object:nil];
}