2013-04-28 60 views
2

我有一個調用MFMailComposeViewController的按鈕。有時候,當我點擊「刪除草稿」時,應用程序崩潰,但有時會正確地解除視圖。我可以'明白爲什麼。這裏是我的代碼:當按下「刪除草稿」時MFMailComposeViewController崩潰

- (IBAction)openEmail:(id)sender { 
if ([MFMailComposeViewController canSendMail]) { 
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
    composer.mailComposeDelegate = (id)self; 
    NSArray *myEmail = [[NSArray alloc] initWithObjects:@"[email protected]", nil]; 
    [composer setToRecipients:myEmail]; 
    [self presentViewController:composer animated:YES completion:nil]; 
    [[composer navigationBar] setTintColor:[UIColor colorWithRed:0.843 green:0.435 blue:0.435 alpha:1]]; 
} 
else { 

    } 
} 

而且這種方法:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     NSLog(@"Mail cancelled"); 

     break; 
    case MFMailComposeResultSaved: 
     NSLog(@"Mail saved"); 

     break; 
    case MFMailComposeResultSent: 
     NSLog(@"Mail send"); 

     break; 
    case MFMailComposeResultFailed: 
     NSLog(@"Mail failed"); 

     break; 
    default: 
     NSLog(@"Mail not sent."); 

     break; 
} 
[self dismissViewControllerAnimated:YES completion:nil]; 
} 

誰能幫助我?

回答

0

你試過:

[self presentModalViewController:_picker animated:YES]; 

通知 'MODAL'?

隨着也:

[self dismissModalViewControllerAnimated:YES]; 
1

我曾經遇到此爲好,並在代碼中的潛在問題的領域可能是這一行:

MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 

這可能是由時間MFMailComposeViewControllerDelegate方法被稱爲,您的composer對象被釋放。相反,嘗試強大的屬性開始MFMailComposeViewController,就像這樣:

self.composer = [MFMailComposeViewController new]; 

您可以設置self.composernil一旦你採取行動的委託方法來釋放MFMailComposeViewController

相關問題