を使用してNSMutableDictionary
、あるクラス(ViewControllerA
)から別のクラス()にを渡す必要があります。次のコードを試しましたが、機能しません。私は実際にに渡しますが、メソッドは呼び出されません。なにか提案を?ありがとう!ViewControllerB
NSNotificationCenter
ViewControllerB
-receiveData
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];
}