【发布时间】:2019-06-06 13:14:58
【问题描述】:
当我收到来自 API 的响应时,我正在显示 UIAlertController。响应后,我想调用其他视图控制器的通知。
我在视图控制器 1 中添加了观察者,如下所示:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdateAthleteDictionaryNotification:) name:@"UpdateAthleteDictionary" object:self.dictProfile];
在视图控制器 2 中,我的代码如下:
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:applicationName
message:[jsonObject valueForKey:@"responseMessage"]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateAthleteDictionary" object:self.dictProfile];
});
[self.navigationController popViewControllerAnimated:YES];
}];
[alert addAction:yesButton];
[self presentViewController:alert animated:YES completion:nil];
但它不调用。所以请你给我建议解决方案。
【问题讨论】:
-
您是否为所有通知添加了删除观察者代码
-
不,如果我删除,那么它将如何从另一个视图调用?
-
这段代码在我的 Mac 上运行良好。你能提供
UpdateAthleteDictionaryNotification的实现吗?self.dictProfile怎么修改?
标签: objective-c iphone notifications presentviewcontroller