我有一个mainViewController.我调用[self pushModalViewController:someViewController],这使得someViewController成为活动视图.
现在我想在mainViewController中调用一个函数,因为someViewController随着[self dismissModalViewController]消失了.
viewDidAppear可能不会被调用,因为视图已经存在,就在模态视图下方.一旦modalView解散自己,如何调用mainViewController中的函数?
非常感谢!
在我的iOS应用程序中,用户可以从列表中选择一个图像,在该图像上显示一个包含图像的模态和删除图像的选项.如果用户选择删除图像,则返回到包含图像列表的原始viewController.我需要刷新原始ViewController以考虑已删除的图像.
当图像被删除到父视图控制器时,我尝试使用NSNotificationCenter进行广播.但是,似乎从未收到广播.
还有其他方法吗?
(我试着按照这里列出的例子,但它似乎没有工作)
以下是我的代码:
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];
Run Code Online (Sandbox Code Playgroud)
MediaPreviewViewController(第二个ViewController):
...
[self deleteImage];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MediaPreviewDismissed" object:nil userInfo:nil];
[self dismissViewControllerAnimated:YES completion:^(){
NSLog(@"dismissed controller");
}];
Run Code Online (Sandbox Code Playgroud)
然后,回到EditStepViewController:
-(void)didDismissMediaPreview{
NSLog(@"dismissed media preview"); // this is never logged!
[self.view setNeedsDisplay]; // refresh view to account for deleted image
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!
objective-c uiviewcontroller nsnotificationcenter ios presentviewcontroller