これは私の最初の試みでありNSNotification
、いくつかのチュートリアルを試しましたが、どういうわけかうまくいきません。
基本的に、ポップアップ サブビュー ( UIViewController
) であるクラス B に辞書を送信し、それが受信されたかどうかをテストしています。
誰が私が間違っているのか教えてください。
クラスA
- (IBAction)selectRoutine:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"Right"
forKey:@"Orientation"];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"PassData"
object:nil
userInfo:dictionary];
createExercisePopupViewController* popupController = [storyboard instantiateViewControllerWithIdentifier:@"createExercisePopupView"];
//Tell the operating system the CreateRoutine view controller
//is becoming a child:
[self addChildViewController:popupController];
//add the target frame to self's view:
[self.view addSubview:popupController.view];
//Tell the operating system the view controller has moved:
[popupController didMoveToParentViewController:self];
}
クラスB
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(receiveData:)
name:@"PassData"
object:nil];
}
- (void)receiveData:(NSNotification *)notification {
NSLog(@"Data received: %@", [[notification userInfo] valueForKey:@"Orientation"]);
}