模态 UIImagePickerController 被解除时的 UIView 通知?

2023-05-16移动开发问题
3

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

问题描述

限时送ChatGPT账号..

有没有办法在模态视图完成关闭时调用代码?

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 通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7