Dismiss ChildView From ParentViewController

天涯浪子 提交于 2020-01-04 04:18:07

问题


I have a parent view that opens a child view like so:

ChildViewController *child = [[ChildViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:child animated:YES];

Which works perfectly fine. I need to dismiss the child view from the parent view but when I do that, nothing happens. Is it because the parent view stops all of its processes when I open the child view? Or is it my code: [child dismissModalViewControllerAnimated:YES]; ? Thanks


回答1:


dismissModalViewControllerAnimated: has to be called on the same object that presentModalViewController:animated: was called on.

In your example, it would need to be [self dismissModalViewControllerAnimated:YES];

If you were dismissing from inside the controller being displayed modally, it would be as @James Bedford described [[self parentViewController] dismissModalViewControllerAnimated:YES];




回答2:


Where are you calling [child dismissModalViewControllerAnimated:YES];? Is this line of code ever being reached?

You could add a target/action to one of your UIControls within your ChildViewController class which uses the inherited parentViewController property to dismiss itself as follows:

[[self parentViewController] dismissModalViewControllerAnimated:YES];



来源:https://stackoverflow.com/questions/5436458/dismiss-childview-from-parentviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!