gpt4 book ai didi

iphone - 线程 1 : EXEC_BAD_ACCESS on MFMailComposeViewController's dismissModalViewController (tried iOS 5. 1、5、4.3)

转载 作者:行者123 更新时间:2023-12-01 17:44:22 26 4
gpt4 key购买 nike

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

我已经检查过了,所有其他问题/答案都与非 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 未保留也可能存在问题。当我使用这个类时,我为 Controller 创建了一个属性。这可能值得一试。

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

关于iphone - 线程 1 : EXEC_BAD_ACCESS on MFMailComposeViewController's dismissModalViewController (tried iOS 5. 1、5、4.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10655540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com