iphone - MFMailComposeViewController 不从 View 中关闭

标签 iphone objective-c cocoa-touch mfmailcomposeviewcontroller

我有以下代码,当调用操作表上的按钮时调用该代码。但是当我按下取消键,然后删除草稿时,它只是 feezes 而不是关闭。我在我的应用程序的其他地方使用了相同的代码,它是从一个 tableview 单元格的选择中调用的,它在那里工作。知道为什么它在这里不起作用吗?

当它卡住时,控制台中也没有错误消息。

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

最佳答案

您需要实现委托(delegate)方法:

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

然后在这个委托(delegate)方法中添加:

[self dismissModalViewControllerAnimated:YES];

它应该工作得很好。

您不必查找结果(仅当您想要显示“谢谢”警报或其他内容时,例如,如果用户确实点击了“发送”)

关于iphone - MFMailComposeViewController 不从 View 中关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6934470/

相关文章:

ios - 在 swift ios 中的 appdelegate 中配置标签栏 Controller 后,我缺少我的标签栏

iphone - 保留用户日历中的事件

iphone - 忽略 iphone 上的 Https SSL 异常

objective-c - Objective C——创建和初始化对象的首选方式

ios - 无法在 IB 中设置 UITableViewCell 的背景颜色

iphone - iTunes Connect,查看总销售额?

iphone - CGAffineTransformMakeRotation错误

objective-c - NSMutableArray,分配还是容量?

ios - 使用 MPMusicPlayerController 防止音量 HUD 出现,可以接受吗?

iphone - UIView "suck"动画