iPhone 应用程序在启动和关闭 MFMailComposeViewController 后出现滞后
-
19-09-2019 - |
题
我有一个使用表视图控制器来显示某些项目的应用程序,单击其中一个项目后,您可以选择通过电子邮件发送该项目。一旦发生这种情况,我使用苹果“MailComposer”提供的代码,并发送邮件。然而,在此之后,表视图中的滚动并不像以前那么顺畅。
我检查了“Leaks”,我的代码中没有泄漏,但是当 MFMailComposeViewController 的模式视图控制器时,存在大量的对象分配,并且当我关闭控制器时,所有对象分配仍然存在。我怎样才能摆脱所有的对象分配?任何帮助将不胜感激。谢谢。
-奥斯卡
更新:
我意识到只有当您单击“收件人”时才会出现延迟:MFMailComposeViewController 上的文本字段并键入一些内容,一旦键入某些内容,就会出现内存泄漏,并且应用程序将会变得缓慢。同样的事情也发生在苹果的 Mail Composer 中。我正在使用模拟器也许这就是原因?还有其他人有类似的经历吗?
我按下控制器的方式是:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *mailSubject = appDelegate.mailTitle;
NSString *mailBody = appDelegate.mailLink;
NSString *formattedString = [NSString stringWithFormat:@"<a href='%@'>%@</a>", mailBody, mailBody];
[picker setSubject:mailSubject];
// Set up recipients
//NSArray *toRecipients = [NSArray arrayWithObject:@"somemail@hotmail.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 (Warning this causes a memory leak aknowledged by Apple)
//NSString *path = [[NSBundle mainBundle] pathForResource:@"news_icon" ofType:@"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
[picker setMessageBody:formattedString isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
并在这里忽略它:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
....
[self dismissModalViewControllerAnimated:YES];
}
解决方案
这是一个已知的内存泄漏 MFMailComposeViewController
类(从 iOS 4.2 SDK 开始)。泄漏甚至可以在 邮件编辑器 Apple 的示例项目。尝试使用分配工具运行应用程序,并注意每次单击取消并再次显示作曲家时总体字节数都会增加。
类似的讨论见下文:
其他提示
请确保您使用
controller.mailComposeDelegate = self;
和不
controller.delegate = self;
不隶属于 StackOverflow