A modal view manager that does not invoke views of a view manager. rejectModalViewControllerAnimated: method

In my modal view controller, I have a button processing method that includes

[self dismissModalViewControllerAnimated: YES]; 

In the view view controller, I override the offsetModalViewControllerAnimated function as follows:

 -(void) dismissModalViewControllerAnimated: (BOOL)animated { NSLog(@"dismiss"); [super dismissModalViewControllerAnimated: animated]; } 

When this button is pressed, the button processing method is called, but rejecting the offsetModalViewControllerAnimated: override function does not cause a call: NSLog (@ "termination"); the statement is not called, and the breakpoint inside the method does not fall.

I tried

 [[self presentingViewController] dismissModalViewControllerAnimated: YES]; 

but that didn't work either. However, the modal view manager is rejected.

Any idea what could be wrong?

+1
ios uikit uiviewcontroller modal-dialog
source share
3 answers

The code that the modal view controller introduced was contained in the UIViewController, which in turn was contained in the UINavigationController. When i called

 [[self presentingViewController] dismissModalViewControllerAnimated: YES]; 

or

 [self dismissModalViewControllerAnimated: YES]; 

A dismissal message is sent to the UINavigationController.

0
source share

This is usually handled by declaring your view controller view as a delegate to your modal controller. The modal VC then called the delegate method in the presented VC to reject the modal transition that it created.

Example:

Modal VC.h:

 @protocol ModalViewControllerDelegate -(void)dismissMyModalViewController; @end 

Modal VC.m:

 // When you want to dismiss the Modal VC [delegate dismissMyModalViewController]; 

View VC.h:

 // Make sure to #import ModalVC.h @property (nonatomic, retain) id <ModalViewControllerDelegate> delegate; 

View VC.m:

 -(void)dismissMyModalViewController { [self dismissModalViewControllerAnimated:YES]; } 
+2
source share

from Programming iOS 6, Matt Neuburg :

On the iPad, when the modalPresentationStyle represented by the view controllers is a UIModalPresentationCurrentContext, you must decide which view controller to represent the presented view controllers representing the ViewController. This will determine which view will be replaced by the presented view of the view controllers. This solution includes another property of the UIViewController that defines the PresentationContext (BOOL). Starting from the view controller to which presentViewController was sent: animated: completion: we go to the chain of controllers of the parent views, look for the one whose definePresentationContext property is YES. If we find one, then one; it will be presentingViewController, and its view will be replaced by the presented view of the view controllers. If we do not find it, everything works as if the presented view controllers modalPresentationStyle were UIModalPresentationFullScreen.

TL DR
1. set definesPresentationContext to true on the desired presentingViewController
2. set modalPresentationStyle to UIModalPresentationCurrentContext on the desired presentedViewController

+2
source share

All Articles