MFMailComposeViewController没有解雇

8 iphone cocoa-touch objective-c mfmailcomposeviewcontroller

我有以下代码在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:@"contact@app.com"]; 

            [picker setToRecipients:toRecipients];

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

            [self presentModalViewController:picker animated:YES];
        }
    }
Run Code Online (Sandbox Code Playgroud)

Or *_*Ron 18

使用:

dismissViewControllerAnimated:completion:
Run Code Online (Sandbox Code Playgroud)

从IOS 6.0中删除:

将此方法添加到您的类:

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

玩得开心


Lud*_*uda 9

可能有几个问题:

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

    @interface yourClass : UIViewController <MFMailComposeViewControllerDelegate>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 不在.m中添加相关功能:

    -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:    (MFMailComposeResult)result error:(NSError*)error {
         [self dismissModalViewControllerAnimated:YES];
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我的错误是没有设置正确的委托,但我修复了它:)现在它适用于我:

     picker.mailComposeDelegate = self;
    
    Run Code Online (Sandbox Code Playgroud)