在我的iOS應用程序中,用戶可以從列表中選擇一個圖像,並在其上顯示包含圖像的模式以及刪除圖像的選項。如果用戶選擇刪除圖像,她將返回到包含圖像列表的原始viewController。然後我需要刷新原始ViewController以考慮刪除的圖像。解除ModalViewController後刷新父視圖控制器
我試過使用NSNotificationCenter廣播時,圖像被刪除到父視圖控制器。但是,似乎廣播從未收到過。
有一些其他的方式來
- 將數據發送回模態後父視圖控制器被駁回,並
- 當模式是從父視圖控制器駁回檢測?
(我試過下面列出here的例子,但它似乎沒有工作)
下面是我的代碼:
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(第二個ViewController):
...
[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
}
預先感謝您的幫助!
你能告訴我你在哪裏 – 2014-09-02 07:26:29