0

这是我的代码

-(IBAction)emailButtonPressed :(UIButton *)sender {

    if (![MFMailComposeViewController canSendMail]) {

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Mail has not been set up on this device" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alertView show];

        return;
}

    NSString *targetFile = [self saveCompleteImage];

    MFMailComposeViewController *mailpicker = [[MFMailComposeViewController alloc] init];
    [mailpicker setMailComposeDelegate:self];

    NSString *mimeType = [StringHelper getMimeType:targetFile];
    [mailpicker addAttachmentData:[NSData dataWithContentsOfFile:targetFile] mimeType:mimeType fileName:[targetFile lastPathComponent]];

    [mailpicker setSubject:[self.currentDocument getNameForUntitled]];
    mailpicker.modalPresentationStyle = UIModalPresentationFormSheet;

    [self.presentedViewController presentViewController:mailpicker animated:YES completion:nil];
}

它没有显示邮件选择器。请告诉我我哪里错了。

4

1 回答 1

-2

问题在于此代码:

[self.presentedViewController presentViewController:mailpicker animated:YES completion:nil];

你需要使用:

[self presentViewController:mailpicker animated:YES completion:nil];

或者

[self.presentingViewController presentViewController:mailpicker animated:YES completion:nil];

检查ModalViewControllers 参考presentedViewController以了解和之间的区别presentingViewController

于 2013-08-16T07:07:26.897 回答