dismissViewControllerAnimated:将我的viewcontroller移动到初始控制器

时间:2014-03-29 11:38:57

标签: ios objective-c xcode mfmailcomposeviewcontroller

我尝试从imageviewcontroller发送邮件,它运行正常,邮件与捕获的图像一起成功发送。当按下发送按钮时,mailcomposeviewcontroller被解除并显示用于登录目的的初始控制器,但实际上它应该移动到当前视图控制器,即imageviewcontroller ..

imageviewcontroller中使用的代码,

- (IBAction)mail_button:(id)sender
{

if ([MFMailComposeViewController canSendMail])
{

    UIGraphicsBeginImageContext(self.view.bounds.size);

    composeViewController = [[MFMailComposeViewController alloc] init];
   // [composeViewController setMailComposeDelegate:self];
    composeViewController.mailComposeDelegate = self;
    // [composeViewController setToRecipients:@[@"example@email.com"]];
    [composeViewController setSubject:@"Dressface Mail"];
    [composeViewController setMessageBody:@"HI i am using dressface application its very awesome you too try this." isHTML:NO];
    UIImage *myimage = [UIImage imageNamed:@"Default.png"];
    NSData *imgdata = UIImagePNGRepresentation(myimage);
    [composeViewController addAttachmentData:imgdata mimeType:@"image/png" fileName:@"Dressfaceimage"];
    [self presentViewController:composeViewController animated:YES completion:nil];
}


}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
    case MFMailComposeResultCancelled:
        NSLog(@"Mail cancelled");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail sent");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail sent failure: %@", [error localizedDescription]);
        break;
    default:
        break;
}

// Close the Mail Interface
[controller dismissViewControllerAnimated:YES completion:nil];
 }

任何人都可以帮我解雇mailcomposeviewcontroller并返回上面放置mail_button的控制器。

2 个答案:

答案 0 :(得分:0)

您也可以在委托方法中编写此行以关闭MFMailComposeViewController

[[controller presentingViewController] dismissViewControllerAnimated:YES completion:nil];

答案 1 :(得分:0)

您不应该忽略在didFinishWithResult方法中传递的MFMailComposeViewController,因为它管理邮件组合视图。你应该改为呼叫

[self dismissViewControllerAnimated:YES completion:nil];

因为它将关闭接收器呈现的视图控制器,即您在其上呈现MFMailComposeViewController的视图控制器。