在我的iOS应用程序中,用户可以从列表中选择一张图片,然后会弹出一个模态框,其中包含该图片和删除图片的选项。如果用户选择删除图片,则返回到原始视图控制器,其中包含图片列表。然后我需要刷新原始视图控制器以考虑已删除的图片。
我尝试使用NSNotificationCenter广播删除图像时向父视图控制器发送数据。但是,似乎没有接收到广播。
有没有其他方法:
1. 在模态框关闭后将数据发送回父视图控制器 2. 检测模态框何时从父视图控制器关闭
(我尝试按照这里中概述的示例操作,但似乎没有起作用)
以下是我的代码:
EditStepViewController(原始视图控制器):
然后,在EditStepViewController中:
我尝试使用NSNotificationCenter广播删除图像时向父视图控制器发送数据。但是,似乎没有接收到广播。
有没有其他方法:
1. 在模态框关闭后将数据发送回父视图控制器 2. 检测模态框何时从父视图控制器关闭
(我尝试按照这里中概述的示例操作,但似乎没有起作用)
以下是我的代码:
EditStepViewController(原始视图控制器):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MediaPreviewViewController *mediaPreviewVC = (MediaPreviewViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MediaPreviewViewController"];
mediaPreviewVC.selectedImageURL = [NSString stringWithFormat:@"%@",gestureRecognizer.view.tag];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mediaPreviewVC];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didDismissMediaPreview)
name:@"MediaPreviewDismissed"
object:nil];
[self presentViewController:navigationController animated:YES completion:nil];
MediaPreviewViewController(第二个视图控制器):
...
[self deleteImage];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MediaPreviewDismissed" object:nil userInfo:nil];
[self dismissViewControllerAnimated:YES completion:^(){
NSLog(@"dismissed controller");
}];
然后,在EditStepViewController中:
-(void)didDismissMediaPreview{
NSLog(@"dismissed media preview"); // this is never logged!
[self.view setNeedsDisplay]; // refresh view to account for deleted image
}
感谢您的帮助!