1

好吧,这已经困扰我一段时间了......

我已经检查过了,所有其他问题/答案都与非 ARC 项目有关。

每当我展示 MFMCvc 并快速取消消息时,我都会在 iPhone 上收到 Thread1:EXEC_BAD_ACCESS 错误消息。在 iPad 上运行良好,或者如果我让它静置一会儿(比如 30 秒或更长时间)

有什么建议吗?(除了设置一个计时器并且在计时器结束之前不解雇?)

顺便说一句,我对 MFMessageComposeViewController 做同样的事情,它在 iPhone 和 iPad 上都可以正常工作。

这是我展示它的代码

if (([action isEqualToString:@"EMail"]) && contact.length>0)
{
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    if([MFMailComposeViewController canSendMail]) {
        [mailViewController setSubject:@""];
        [mailViewController setMessageBody:@"" isHTML:NO];
        [mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
        [mailViewController setMailComposeDelegate:self];
        [self presentModalViewController:mailViewController animated:NO];
    }
}

这就是我忽略它的地方

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        switch (result)
        {
            case MFMailComposeResultCancelled:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Cancelled"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            case MFMailComposeResultFailed:
            {
                NSLog(@"Error");
            }
                break;
            case MFMailComposeResultSent:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Sent"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            case MFMailComposeResultSaved:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Saved"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];
            }
                break;
            default:
                break;
        }
        [self dismissModalViewControllerAnimated:NO];
    }
4

2 回答 2

5

1) 行:[self dismissModalViewControllerAnimated:NO];- 是否需要:[controller dismissModalViewControllerAnimated:NO];?您想要关闭 MFMailComposeViewController。

2) MFMailComposeViewController 未保留也可能存在问题。当我使用这个类时,我为控制器创建了一个属性。这可能值得一试。

// in the interface definition
 @property (nonatomic, strong) MFMailComposeViewController* mailComposer;

接着

// at creation time
if (([action isEqualToString:@"EMail"]) && contact.length>0)

if(![MFMailComposeViewController canSendMail]) return; // bail early if can't send mail

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
[mailViewController setSubject:@""];
[mailViewController setMessageBody:@"" isHTML:NO];
[mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
[mailViewController setMailComposeDelegate:self];
[self presentModalViewController:mailViewController animated:NO];

[self setMailComposer: mailViewController];
// if not using ARC then:  [mailViewController release];

然后在 didFinish

 [[self mailComposer] dismissModalViewControllerAnimated:YES];
 [self setMailComposer: nil];
于 2012-05-18T18:20:23.533 回答
1

[self dismissModalViewControllerAnimated:NO]移动到 didFinishWithResult 函数的顶部。换句话说,在显示警报视图之前关闭邮件视图。我不确定这是否会消除您的崩溃,但无论如何,您应该这样做。

于 2012-05-18T16:39:18.833 回答