2013-09-24 28 views
1

我正在開發iOS 7的應用程序,並使用MFMailComposerViewController如何在iOS 7上使用MFMailComposerViewController?

我已經嘗試了一切,但dismissViewController:withAnimated不起作用。

有時會在第一次使用方法presentViewCOntroller:withAnimated:completion顯示viewController時自動調用委託。

我的應用程序基於導航,這就是爲什麼我認爲問題也與UINavigationController有關。

 -(void)sendMail{ 

if ([MFMailComposeViewController canSendMail]) { 

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

    [picker setSubject:@"Hello from California!"]; 

    // Set up recipients 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [picker setToRecipients:toRecipients]; 
    [picker setCcRecipients:ccRecipients]; 
    [picker setBccRecipients:bccRecipients]; 



    // Fill out the email body text 
    NSMutableString *emailBody =[NSMutableString stringWithString: @"<table border=1 align=\"center\"><tr><th>EventDate</th><th>EventDay</th><th>EventTime</th><th>Speaker</th><th>topic</th></tr>"]; 

    for (int i=0; i<5; i++) { 
     NSString *eventDate=[NSString stringWithFormat:@"<tr><td>%@</td>",@"12/11"]; 
     NSString *eventDay=[NSString stringWithFormat:@"<td>%@</td>",@"Sunday"]; 
     NSString *eventTime=[NSString stringWithFormat:@"<td>%@</td>",@"12:10 pm"]; 
     NSString *eventSpeaker=[NSString stringWithFormat:@"<td>%@</td>",@"RajVeer"]; 
     NSString *eventTopic=[NSString stringWithFormat:@"<td>%@</td>",@"nano-technology"]; 
     NSString *dataString=[NSString stringWithFormat:@"%@%@%@%@%@</tr>",eventDate,eventDay,eventTime,eventSpeaker,eventTopic]; 
     [emailBody appendString:dataString]; 
    } 
    NSString *[email protected]"</table>"; 
    [emailBody appendString:lastTable]; 
    NSLog(@"%@",emailBody); 
    [picker setMessageBody:emailBody isHTML:YES]; 

    [self presentViewController:picker animated:YES completion:NULL]; 


} 
+3

向我們展示你正在使用呈現和罷免視圖控制器的代碼。 –

+2

在iOS 7上,它的工作方式是在早期版本的iOS上運行(剛測試過)。它應該是你的代碼有問題。 –

回答

0

使用此代碼從iOS的6.0 [self presentModalViewController:<#(UIViewController *)#> animated:<#(BOOL)#>]呈現MFMailComposeViewController

[self presentViewController:mailComposerObject animated:YES completion:NULL]; 

對於駁回MFMailComposeViewController

#pragma mark - MFMailComposeViewControllerDelegate 
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError*)error { 
[self dismissViewControllerAnimated:YES completion:NULL]; 
} 

已棄用。

+3

[self dismissViewControllerAnimated:YES completion:NULL];不適用於iOS 7 – Ravee10

1

這應該做的伎倆:

#pragma mark MFMailComposeViewControllerDelegate 

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 
    [controller dismissViewControllerAnimated:YES completion:nil]; 
} 
相關問題