MFMailComposeViewController不从视图中取消 [英] MFMailComposeViewController Not Dismissing From View
问题描述
我有以下代码,当调用操作表上的按钮时调用。但是当我按取消,然后删除草稿,它只是冻结,不会关闭。我使用相同的代码在我的应用程序的其他地方,并从一个选择的tableview单元格,它的工作找到那里。任何想法为什么它不工作这里?
Ther在控制台冻结时也没有错误msg。
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];
//设置收件人
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];
//将图像附加到电子邮件
// NSString * path = [[NSBundle mainBundle] pathForResource:@rainyofType:@png];
// NSData * myData = [NSData dataWithContentsOfFile:path];
// [picker addAttachmentData:myData mimeType:@image / pngfileName:@rainy];
//填写电子邮件正文文本
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然后在这个委托方法中添加: pre> [self dismissModalViewControllerAnimated:YES];
它应该工作正常。
您不必查找结果(仅当您想要显示谢谢警报或某些事情时,例如,如果用户确实命中发送)
I have the following code that is called when a button on an action sheet is called. But when I press cancel, then delete draft, it just feezes and does not dismiss. I use the same code elsewhere in my app and its called from a select of a tableview cell and it works find there. Any ideas why it isn't working here?
Ther is also no error msg in the console when it freezes.
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];
}
You need to implement the delegate method:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
Then in this delegate method add:
[self dismissModalViewControllerAnimated:YES];
and it should be working just fine.
You don't have to look for the result (only if you want to display a "Thank you" alert or something, for example, if the user did indeed hit Send)
这篇关于MFMailComposeViewController不从视图中取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!