[英]Thread 1: EXEC_BAD_ACCESS on MFMailComposeViewController's dismissModalViewController (tried iOS 5.1 , 5 , 4.3)
好吧,這已經困擾了我一段時間了...
我已經檢查過,所有其他問題/答案都與非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];
}
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];
將[self dismissModalViewControllerAnimated:NO]移動到didFinishWithResult函數的頂部。 換句話說,在顯示警報視圖之前,請關閉郵件視圖。 我不確定這是否可以消除崩潰,但是無論如何,您應該這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.