[英]Thread 1: EXEC_BAD_ACCESS on MFMailComposeViewController's dismissModalViewController (tried iOS 5.1 , 5 , 4.3)
Ok, this has been haunting me for a while now... 好吧,这已经困扰了我一段时间了...
I have checked and all the other questions/answers are with non ARC projects. 我已经检查过,所有其他问题/答案都与非ARC项目有关。
Whenever I present the MFMCvc and I quickly cancel the message I get the Thread1:EXEC_BAD_ACCESS error message on iPhones. 每当我出现MFMCvc并迅速取消消息时,我在iPhone上都会收到Thread1:EXEC_BAD_ACCESS错误消息。 Works fine on the iPad or if I let it sit for a bit (say 30 secs or more)
在iPad上工作正常,或者如果我静置一会儿(例如30秒或更长时间)
Any advise? 有什么建议吗? (other than putting a timer and not dismissing until timer's up?)
(除了放置计时器,直到计时器启动后才解雇?)
BTW I'm doing the same with MFMessageComposeViewController and it works fine on both iPhone and iPad. 顺便说一句,我用MFMessageComposeViewController做同样的事情,它在iPhone和iPad上都能正常工作。
Here is my code to present it 这是我的代码来展示它
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];
}
}
And here is where I dismiss it 这是我解雇的地方
-(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];
}
1) Doesn't the line: [self dismissModalViewControllerAnimated:NO];
1)不行:
[self dismissModalViewControllerAnimated:NO];
- need to be: [controller dismissModalViewControllerAnimated:NO];
-需要为:
[controller dismissModalViewControllerAnimated:NO];
? ? You are wanting to dismiss the MFMailComposeViewController.
您要关闭MFMailComposeViewController。
2) There may also be an issue with the MFMailComposeViewController not being retained. 2)MFMailComposeViewController可能还没有保留。 When I've used this class I've created a property for the controller.
当我使用此类时,我为控制器创建了一个属性。 This might be worth trying.
这可能值得尝试。
// in the interface definition
@property (nonatomic, strong) MFMailComposeViewController* mailComposer;
and then 接着
// 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];
and then in the didFinish 然后在didFinish中
[[self mailComposer] dismissModalViewControllerAnimated:YES];
[self setMailComposer: nil];
Move [self dismissModalViewControllerAnimated:NO] to the top of your didFinishWithResult function. 将[self dismissModalViewControllerAnimated:NO]移动到didFinishWithResult函数的顶部。 In other words, dismiss the mail view before showing the alert view.
换句话说,在显示警报视图之前,请关闭邮件视图。 I'm not sure if this will eliminate your crash, but regardless, you should do this.
我不确定这是否可以消除崩溃,但是无论如何,您应该这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.