UIView notification when firing a modal UIImagePickerController?

Is there a way to call code when the modal view is completed by firing?

EDIT:

Sorry, I didnโ€™t specify earlier. I am trying to reject the UIImagePickerController and then show the MFMailComposeViewController and attach the image data to the email. When i try to call

[self presentModalViewController: mailController]

right after

[self dismissModalViewController];

I get errors and the like.

+1
source share
3 answers

You use the delegate template for modal presentation to let you know who introduced it when it is finished.

MyModalViewController.h:

 @protocol MyModalViewControllerDelegate; @interface MyModalViewController : UIViewController { id<MyModalViewControllerDelegate> delegate; } @property (nonatomic, assign) id<MyModalViewControllerDelegate> delegate; @end @protocol MyModalViewControllerDelegate - (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController; @end 

MyModalViewController.m:

 @synthesize delegate; // Call this method when the modal view is finished - (void)dismissSelf { [delegate myModalViewControllerFinished:self]; } 

ParentViewController.h:

 #import "MyModalViewController.h" @interface ParentViewController : UIViewController <MyModalViewControllerDelegate> { } 

ParentViewController.m:

 - (void)presentMyModalViewController { MyModalViewController* myModalViewController = [[MyModalViewController alloc] initWithNibName:@"MyModalView" bundle:nil]; myModalViewController.delegate = self; [self presentModalViewController:myModalViewController animated:YES]; [myModalViewController release]; } - (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController { [self dismissModalViewControllerAnimated:YES]; } 

EDIT:

I have not used the UIImagePickerController , but looking at the docs, it looks like you already have most of the code made for you, since there is an existing UIImagePickerControllerDelegate that has three different โ€œrejectsโ€ of delegate responses (although one of them is deprecated). Therefore, you must make your ParentViewController class (whatever it is) implement the UIImagePickerControllerDelegate template, and then implement these methods. Although each method will do something different (since you have to process it when the user really selects the image or cancels it), each of them will do the same at the end: call dismissModalViewControllerAnimated: to reject the collector.

+5
source

Do you have to somehow reject the modalViewController? Either UIButton, or by code:

 - (void)dismissModalViewControllerAnimated:(BOOL)animated 

In IBAction (e.g. delegation) for a UIButton or the above method, any code you want is called.

0
source

I donโ€™t think there is a special notice that can still be signed in order to know when the animation stops, ... BUT. You can implement viewDidAppear: in the view controller that introduced the modal view. This is what I do when I use (for UIImagePickerController very similar) ABPeoplePickerNavigationController.

In the callback from the people collector, I remember how a person tapped on the instance variable in the collector, for example:

 - (void)callbackFromModalView:(id)dataFromModalView { // remember dataFromModalView as I need it when dismissed self.dataFromModalView = dataFromModalView; // now initiate dismissal [self dismissModalViewControllerAnimated:YES]; } 

then in your view controller do the following:

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (self.dataFromModalView) { //...present now view here // don't forget to reset this one self.dataFromModalView = nil; } } 

you use a combination of viewWillAppear: and the dataFromModalView property as a "modal view disable notification".

0
source

Source: https://habr.com/ru/post/917145/


All Articles