2011-11-05 77 views
1
- (void) mailshareClick:(UIButton *)sender 
{ 
    NSString *_message = @"wait for set up Mail"; 
    [self waitForWhile:_message]; 
    if ([MFMailComposeViewController canSendMail]){ 
     [NSThread detachNewThreadSelector:@selector(mailFunction) toTarget:self withObject:nil]; 
    } 
    else { 
     _message = @"Please set Mail account"; 
     [self remove:_message]; 
    } 
} 
- (void) mailFunction 
{ 
    NSData *data = nil; 
    if ([self.files.imageArr count]>0) 
    { 
     XXImage *single = [self.files.imageArr objectAtIndex:0]; 
     UIImage *image = [[SDImageCache sharedImageCache] imageFromKey:[[single.imagearray objectAtIndex:0] columnImage]]; 
     data = [UIImageJPEGRepresentation(image, 1.0f) retain]; 
    } 
    [self performSelectorOnMainThread:@selector(mailFinished:) withObject:data waitUntilDone:YES];  
    [data release]; 
} 
- (void) mailFinished:(NSData *)_data 
{ 
    if ([MFMailComposeViewController canSendMail]){ 
     NSData *data = [_data retain]; 
     MFMailComposeViewController *message = [[MFMailComposeViewController alloc] init]; 
     //Title 
     [message setSubject:self.files.title]; 
     //Body 
     [message setMessageBody:@"111" isHTML:YES]; 

     [message setToRecipients:[NSArray arrayWithObject:@"mail"]]; 
     //Content 
     if (data != nil) { 
      NSString *picStr = [[NSString alloc] initWithFormat:@"%@%@",OutsideWebsite_Normal,self.files.middlePicPath]; 
      [message addAttachmentData: data mimeType: @"" fileName:picStr]; 
      [picStr release]; 
      [data release]; 
     } 
     message.mailComposeDelegate = self; 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     { 
      message.modalPresentationStyle = UIModalPresentationFormSheet; 
     } 
     [self presentModalViewController:message animated:YES]; 

     [self remove:@"Set up Ok"]; 
     [message release]; 
    } 
} 
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    switch (result) { 
     case MFMailComposeResultSent: 
     { 
      NSLog(@"MFMailComposeResultSent"); 
      break; 
     } 
     case MFMailComposeResultSaved: 
     { 
      NSLog(@"MFMailComposeResultSaved"); 
      break; 
     } 
     case MFMailComposeResultFailed: 
     { 
      NSLog(@"MFMailComposeResultFailed"); 
      break; 
     } 
     case MFMailComposeResultCancelled: 
     { 
      NSLog(@"MFMailComposeResultCancelled"); 
      break; 
     } 
     default: 
      break; 
    } 
    [self performSelector:@selector(delayDismissModalView) withObject:nil afterDelay:1]; 
} 
-(void)delayDismissModalView 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

調用經過幾次電子郵件方式,將有上崩潰MFMailComposeViewController爲iPad

  • [MFSearchResultsViewController哈希]:消息發送到釋放實例 或者

  • [MFMailComposeViewController哈希]:發送到釋放實例的消息

崩潰。

正如你所想的那樣,MFSearchResultsViewController函數是什麼。

是否可以解決問題,請幫我一下。

回答

1

您必須爲郵件控制器設置Degate。如果您將代表設置爲「自我」,請確保「自我」具有<MFMailComposeViewControllerDelegate>。如果所有這些都無法使其工作,請確保您沒有撥打presentModalViewController兩次。