2012-03-25 9 views
0

私のコードでMFMessageComposeViewControllerを実装しましたが、今、電子メールを送信できるうちに、ドラフトを保存したり、削除したり、電子メールを送信したりしても、View Controllerは破棄されません。また、ブレークポイントを追加しようとしましたが、それを解除するコードは実行されません。MFMailComposeViewControllerが解除されない

- (IBAction)sendEmail:(id)sender { 

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 

if(mailClass != nil) 
{ 
    if ([mailClass canSendMail]) 
    { 
     [self displayComposerSheet]; 
    } 
    else 
    { 
     [self launchMailAppOnDevice]; 
    } 

} 
else 
{ 
    [self launchMailAppOnDevice]; 
} 
} 

- (void)displayComposerSheet 
{ 
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 

NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

[picker setEditing:YES]; 
[picker setToRecipients:toRecipients]; 

[self presentModalViewController:picker animated:YES]; 
picker.mailComposeDelegate = self; 
} 

- (void)launchMailAppOnDevice 
{ 
NSString *address = @"mailto:[email protected]"; 

NSString *email = [NSString stringWithFormat:@"%@", address]; 
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 
} 

-(void)mailComposeController:picker didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
[self dismissModalViewControllerAnimated:YES]; 
} 

答えて

0

presentModalViewControllerを呼び出す前にデリゲートを設定してみてください。

0

モーダルビューを表示する前にpicker.mailComposeDelegate = selfを設定してください。 それはあなたを助けるかもしれません。

+0

私は上記のことを行いましたが、回答として設定できませんでした。とにかくありがとう! – user1222053

関連する問題