代码之家  ›  专栏  ›  技术社区  ›  Oscar Gomez

iPhone应用程序在启动和解除mfmailcomposeviewController后会滞后

  •  2
  • Oscar Gomez  · 技术社区  · 15 年前

    我有一个应用程序,它使用表视图控制器来显示一些项目,单击其中一个项目后,您可以选择通过电子邮件发送此项目。一旦发生这种情况,我就使用苹果“邮件编辑器”提供的代码,并发送邮件。然而,在这之后,表视图中的滚动就不像以前那样平滑了。

    我检查了“leaks”,代码中没有泄漏,但是当mfmailcomposeviewcontroller的模式视图控制器,以及当我解除控制器时,所有的对象分配仍然存在时,会有大量的对象分配。我怎样才能摆脱所有的对象分配呢?任何帮助都将不胜感激。谢谢您。

    -奥斯卡

    更新:

    我已经意识到,只有当您单击mfmailcomposeviewController上的to:textfield并键入某些内容时,才会发生延迟,一旦键入了某些内容,就会出现内存泄漏,应用程序也会迟缓。同样的事情也发生在苹果的邮件作曲家身上。我用的是模拟器也许这就是为什么?.其他人有席米拉的经验吗?

    我给控制器施压的方式是:

    -(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];
    }
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   Imran Raheem    13 年前

    这是已知的内存泄漏 MFMailComposeViewController 类(从iOS 4.2 SDK开始)。甚至可以在 邮件作曲家 苹果公司的样本项目。尝试使用分配工具运行应用程序,并注意到每次单击“取消”并再次显示作曲家时,总字节数都在增加。

    类似讨论见下文:

    1. http://discussions.apple.com/thread.jspa?threadID=2158170

    2. https://devforums.apple.com/thread/23510?tstart=15

    3. https://devforums.apple.com/message/121093#121093

        2
  •  0
  •   mxg    14 年前

    确保使用

    controller.mailComposeDelegate = self;
    

    而不是

    controller.delegate = self;