2013-08-16 74 views
0

這裏是我的代碼MFMailComposeViewController - 無法presentViewController

-(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]; 
} 

這不是呈現mailpicker。請告訴我我在哪裏錯了。

回答

-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 Reference瞭解presentedViewControllerpresentingViewController

之間的區別
+1

如果沒有任何解釋,調整不是很有用。 – Brad

相關問題