开发者

Dismiss ChildView From ParentViewController

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]; ? T开发者_JS百科hanks


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];


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];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜