Question

Hi have this problem of a view that cannot be closed. I have read a lot of Q&As and I tried

[self dismissModalViewControllerAnimated:YES]

once it did not work I have tried calling the parent view:

[self.parentViewController dismissModalViewControllerAnimated:YES];

then there was a discussion on what is working on iOS 5 and later and I tried this code:

 if ([self respondsToSelector:@selector(presentingViewController)]){
     [self.presentingViewController dismissModalViewControllerAnimated:YES];
 } else {
     [self.parentViewController dismissModalViewControllerAnimated:YES];
 }

The last thing I have tried was adding the following code to make the call from the main thread:

[self performSelectorOnMainThread:@selector(dismissSelf) withObject:nil waitUntilDone:NO];

Eventually, I have no solution to the problem as nothing works for me. I will be glad to see the "killer" line that makes it to work.

Thanks, Simon

Was it helpful?

Solution

Your problem (based on your comment) is you are technically not using a modal, you are using a subview!

If you want to use a modal you need to do:

[self presentModalViewController:self.fav animated:YES];

to present your controller, instead of: [self.view addSubview:_fav.view];

Then your dismissal will work (many of your solutions will work):

[self dismissModalViewControllerAnimated:YES];

Otherwise if you do wish to use a subview you would need to do this to remove it:

[self.fav.view removeFromSuperview];

(It also looks like you are using ivars. If you wish to keep using them then replace self.fav with _fav)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top