簡體   English   中英

MFMailComposeViewController不從視圖中刪除

[英]MFMailComposeViewController Not Dismissing From View

我有以下代碼,當調用操作表上的按鈕時調用該代碼。 但是當我按下取消,然后刪除草稿時,它只是過時而且不會消失。 我在我的應用程序的其他地方使用相同的代碼,並從一個tableview單元格中調用它,它可以在那里找到它。 任何想法為什么它不在這里工作?

當凍結時控制台中的Therg也沒有錯誤消息。

if([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Dr. Chrono Support"];

    NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString* versionNum = [infoDict objectForKey:@"CFBundleVersion"];
    NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
    NSString *text = [NSString stringWithFormat:@"%@ %@",appName,versionNum];

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"contact@drchrono.com"]; 
    //NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    //NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

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

    // Attach an image to the email
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
    //NSData *myData = [NSData dataWithContentsOfFile:path];
    //[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

    // Fill out the email body text
    NSString *emailBody = text;
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

您需要實現委托方法:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

然后在這個委托方法中添加:

[self dismissModalViewControllerAnimated:YES];

它應該工作得很好。

您不必查找結果(僅當您要顯示“謝謝”警報或其他內容時,例如,如果用戶確實點擊了發送)

使用以下代碼

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{

    switch (result)
    {

        case MFMailComposeResultCancelled: 
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the Drafts folder");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
            break;
        default:
            NSLog(@"Mail not sent");
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM