模态UIImagePickerController被解除时的UIView通知? [英] UIView notification when modal UIImagePickerController is dismissed?

查看:89
本文介绍了模态UIImagePickerController被解除时的UIView通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当模态视图完成解雇时,有没有办法调用代码?

Is there a way to call code when a modal view is finished dismissing?

编辑:

对不起,我之前没有澄清过。我正在尝试解除UIImagePickerController,然后显示MFMailComposeViewController并将图像数据附加到电子邮件中。当我尝试拨打

I'm sorry, I didn't clarify earlier. I'm trying to dismiss a UIImagePickerController and then show a MFMailComposeViewController and attach the image data to the email. When I try to call

[self presentModalViewController:mailController]

[self dismissModalViewController];

我得到错误等。

推荐答案

您可以使用模式视图的委托模式通知在完成时提供它的人。

You use a delegate pattern for the modal view to inform whoever presented it when it's finished.

MyModalViewController.h:

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:

MyModalViewController.m:

@synthesize delegate;

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

ParentViewController.h:

ParentViewController.h:

#import "MyModalViewController.h"

@interface ParentViewController : UIViewController <MyModalViewControllerDelegate>
{
}

ParentViewController.m:

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

编辑:

我没有使用过 UIImagePickerController ,但是查看文档,看起来你已经为你完成了大部分代码,就像那里一样是现有的 UIImagePickerControllerDelegate 具有三个不同解雇委托回调的类(尽管有一个不推荐使用)。因此,您应该使 ParentViewController 类(无论是什么)实现 UIImagePickerControllerDelegate 模式,然后实现这些方法。虽然每个方法都会做一些不同的事情(因为你必须在用户实际选择一个图像时处理它们,或者如果它们取消了),它们每个都会在最后做同样的事情:call dismissModalViewControllerAnimated:解雇选择器。

I haven't used UIImagePickerController, but looking at the docs, it looks like you already have most of the code done for you, as there is an existing UIImagePickerControllerDelegate class that has three different "dismissal" delegate callbacks (although one is deprecated). So you should make your ParentViewController class (whatever that is) implement the UIImagePickerControllerDelegate pattern and then implement those methods. While each method will do something different (since you have to handle when the user actually selects an image, or if they cancel), they each will do the same thing at the end: call dismissModalViewControllerAnimated: to dismiss the picker.

这篇关于模态UIImagePickerController被解除时的UIView通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆