Jon*_*rft 0 objective-c nsnotifications nsnotificationcenter ios
这是我的第一次尝试NSNotification,试过几个教程,但不知怎的,它不起作用.
基本上我正在向B类发送一个字典,它是弹出子视图(UIViewController)并测试是否已收到.
谁能告诉我我做错了什么?
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];
}
Run Code Online (Sandbox Code Playgroud)
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"]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
502 次 |
| 最近记录: |