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

查看:14
本文介绍了模态 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]

紧接着

[selfdismissModalViewController];

我收到错误等.

推荐答案

您使用模式视图的委托模式来通知呈现它的人何时完成.

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 模式,然后实现这些方法.虽然每个方法都会做一些不同的事情(因为你必须处理用户实际选择图像时,或者如果他们取消),他们每个人都会在最后做同样的事情:调用 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天全站免登陆