MFMailComposeViewController 不解雇

发布于 2024-12-08 19:55:20 字数 918 浏览 3 评论 0原文

我有在 didSelectRowAtIndexPath 中调用的以下代码。问题是,当我点击取消按钮时,它提示保存草稿或放弃。但是当我单击其中任何一个时,视图都不会消失。我在 iOS 5 之前的应用程序中使用了相同的代码,并且效果很好。有什么想法吗?我在界面中有 MFMailComposeViewController 委托协议。

    if (indexPath.row == 0)
    {
        if([MFMailComposeViewController canSendMail])
        {

            MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
            picker.mailComposeDelegate = self;

            [picker setSubject:@"Support"];

            NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

            [picker setToRecipients:toRecipients];

            NSString *emailBody = text;
            [picker setMessageBody:emailBody isHTML:NO];

            [self presentModalViewController:picker animated:YES];
        }
    }

I have the following code that gets called in didSelectRowAtIndexPath. The issue is, when I click the cancel button, it prompts for save draft or discard. But when I click either, the view does not dismiss. I've used the same code in a pre iOS 5 app and it dismissed fine. Any ideas? I have the MFMailComposeViewController delegate protocol in the interface.

    if (indexPath.row == 0)
    {
        if([MFMailComposeViewController canSendMail])
        {

            MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
            picker.mailComposeDelegate = self;

            [picker setSubject:@"Support"];

            NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

            [picker setToRecipients:toRecipients];

            NSString *emailBody = text;
            [picker setMessageBody:emailBody isHTML:NO];

            [self presentModalViewController:picker animated:YES];
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦幻之岛 2024-12-15 19:55:20

使用:

dismissViewControllerAnimated:completion:

从 IOS 6.0 开始已弃用:

将此方法添加到您的类中:

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self dismissModalViewControllerAnimated:YES];
}

玩得开心

Use:

dismissViewControllerAnimated:completion:

DEPRECATED FROM IOS 6.0:

Add this method to your class:

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self dismissModalViewControllerAnimated:YES];
}

Have fun

嘿看小鸭子会跑 2024-12-15 19:55:20

可能存在几个问题:

  1. 未在 .h 中添加协议实现

    @interface yourClass : UIViewController ;
    
  2. 不在.m中添加相关函数:

    -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)结果错误:(NSError*)error {
         [自我解雇ModalViewControllerAnimated:是];
    }
    
  3. 我的错误是没有设置正确的委托,但我修复了它:),现在它对我有用:

     picker.mailComposeDelegate = self;
    

There could be several problems:

  1. Not adding protocol implemantation in the .h

    @interface yourClass : UIViewController <MFMailComposeViewControllerDelegate>
    
  2. Not adding the relevant function in .m:

    -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:    (MFMailComposeResult)result error:(NSError*)error {
         [self dismissModalViewControllerAnimated:YES];
    }
    
  3. My error was not setting the correct delegate, but I fixed it :) and now it works for me:

     picker.mailComposeDelegate = self;
    
初见你 2024-12-15 19:55:20

“dismissModalViewControllerAnimated:”在 iOS 6.0 中已弃用

iOS 7 使用:

“dismissViewControllerAnimated:completion:”

"dismissModalViewControllerAnimated:"is deprecated in iOS 6.0

iOS 7 use:

"dismissViewControllerAnimated:completion:"

余生再见 2024-12-15 19:55:20

我在这里更详细地描述了该问题以及解决该问题的方法:https://stackoverflow。 com/a/13576408/691660

我不确定旅达是否抓住了问题的核心。无论您是否指定委托都没有区别,这在模态+模态 MFMailComposeViewController 实例的情况下不起作用。

I've described the problem and the way it can be solved more detailed here: https://stackoverflow.com/a/13576408/691660

I am not sure if Luda caught the core of the problem. No difference whether you specify the delegate or not, that does not work in case of modal+modal MFMailComposeViewController instance.

玻璃人 2024-12-15 19:55:20

Swift 实现:

确保您的 MFMailComposeViewController 协议和委托在每次执行其函数时都被调用。

这解决了 MFMailComposeViewController 不被解雇的问题。

     let subj = "Test"
     let messageBody = "Test"
     let toRecipents = ["[email protected]"]
     let mc: MFMailComposeViewController = MFMailComposeViewController()
     mc.mailComposeDelegate = self
     mc.setSubject(subj)
     mc.setMessageBody(messageBody, isHTML: true)
     mc.setToRecipients(toRecipents)
     self.present(mc, animated: true, completion: nil)

Swift Implementation:

Make sure your MFMailComposeViewController protocol and delegate is being called every time its function being executed.

This solves the issue of MFMailComposeViewController not being dismissed.

     let subj = "Test"
     let messageBody = "Test"
     let toRecipents = ["[email protected]"]
     let mc: MFMailComposeViewController = MFMailComposeViewController()
     mc.mailComposeDelegate = self
     mc.setSubject(subj)
     mc.setMessageBody(messageBody, isHTML: true)
     mc.setToRecipients(toRecipents)
     self.present(mc, animated: true, completion: nil)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文