4

iPhone 開発は初めてです。タブバー ベースのアプリケーションを作成しました。最初に、メール コンポーザを表示したいと考えています。表示はできたのですが、キャンセルボタンと送信ボタンが効かず、どこが悪いのかわかりません。助けてください。これが私のコードです。

- (void)viewDidLoad 
{
    [super viewDidLoad];
    [self displayComposerSheet];    
}

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

   [[picker navigationBar] setTintColor:[UIColor blackColor]];

   picker.mailComposeDelegate = self;

   if ([MFMailComposeViewController canSendMail]) 
   {

            [picker setToRecipients:[NSArray arrayWithObjects:@"name@gmail.com",nil]];

            [picker setSubject:@"Sample"];

   }
   [self.view addSubview:picker.view];
   [self presentModalViewController:picker animated:YES];

}

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{

    [self dismissModalViewControllerAnimated:YES];

 }
4

4 に答える 4

1

メール コンポーザを 2 回表示しています。

次の行を削除します。

[self.view addSubview:picker.view];

次の行を次のように置き換えます。

[self.navigationController presentModalViewController:picker animated:YES];
于 2010-03-27T21:05:49.230 に答える
1

mailcomposser のサブビューのみを追加する場合は、それを self.view から削除する必要があります。コードでは、サブビューを追加して存在します。

あなたが使用している場合は[self.view addSubview:picker.view];、それを取り除くために試してみてください。

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
    [controller.view removeFromSuperview];

 }

私はまだ使用することをお勧めします

[self.navigationController presentModalViewController:picker animated:YES];現在の MFMailComposeViewController の場合、

を使用[self dismissModalViewControllerAnimated:YES];して、それを却下します。

于 2013-12-11T06:02:57.307 に答える
0

次のコードを使用します。

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:@"niftyapplications@gmail.com", @"support@niftysol.com", nil]; 
[controller setToRecipients:toRecipients];
[controller setTitle:@"Contact Us"];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:controller animated:YES];


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
     [self becomeFirstResponder];
     NSString *strMailResult;
     switch (result)
     {
        case MFMailComposeResultCancelled:
        strMailResult = NSLocalizedString(@"E-Mail Cancelled",@"");
        break;
        case MFMailComposeResultSaved:
        strMailResult = NSLocalizedString(@"E-Mail Saved",@"");
        break;
        case MFMailComposeResultSent:
        strMailResult = NSLocalizedString(@"E-Mail Sent",@"");
        break;
        case MFMailComposeResultFailed:
        strMailResult = NSLocalizedString(@"E-Mail Failed",@"");
        break;
        default:
        strMailResult = NSLocalizedString(@"E-Mail Not Sent",@"");
        break;
     }

     UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ISO Audit",@"") message:strMailResult delegate:self  cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil];
     [alertView show];
    [self dismissModalViewControllerAnimated:YES];
}
于 2013-12-11T05:48:12.510 に答える
0

MFMailComposeViewController のデリゲートを設定する

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

mailcomposer.mailComposeDelegate = self; 

そして、このデリゲートメソッドを使用してください

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
}
于 2013-12-11T05:39:22.273 に答える