Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 353
Preston Avatar asked Dec 18 '25 14:12

Preston


2 Answers

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

like image 131
Nick F Avatar answered Dec 21 '25 05:12

Nick F


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

like image 34
James Bedford Avatar answered Dec 21 '25 05:12

James Bedford