1

こんにちは、2 つの異なる MFMailComposeViewController 同じビューがあり、2 つの異なるメール アドレスに書き込みます。それぞれに 1 つの異なる成功アラートを設定する必要があります。タグでやってみましたが、MFMailComposeViewController でタグが使えませんか?

どうすればそれができますか?

それは私の 2 番目の MFMailComposeViewController です

-(IBAction)inviaMail2{
MFMailComposeViewController *mail2 = [[MFMailComposeViewController alloc] init];
mail2.mailComposeDelegate = self;

if([MFMailComposeViewController canSendMail]){
    [mail2 setToRecipients:[NSArray arrayWithObjects:@"piccolericette@alternativeindustries.it", nil]];
    [self presentModalViewController:mail2 animated:YES];

}
[mail2 release];
 }

 - (void)mailComposeController2:(MFMailComposeViewController *)controller2 didFinishWithResult:(MFMailComposeResult)result2 error:(NSError *)error{

[self dismissModalViewControllerAnimated:YES];

if (result2 == MFMailComposeResultFailed){
    UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Messaggio non inviato." message:@"Non è stato possibile inviare la tua mail, verifica la tua connessione internet e riprova." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert2 show];
    [alert2 release];
}
else {
    UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Messaggio inviato." message:@"Grazie per avermi contattato, ti risponderò il più presto possibile." delegate:self cancelButtonTitle:@"Prego" otherButtonTitles:nil];
    [alert2 show];
    [alert2 release];
}
}
4

1 に答える 1

3

Update: I somehow missed that you can access controller.view.tag which is closer to what OP wanted.
I'll keep my generic answer since it may apply to other situations where you don't have a custom field you can use.

Original Answer: This is more of a generic design solution (workaround?) to this problem. I'm not sure if MFMailComposeViewController has any dynamic user-info field you can use to differentiate, but you can define 2 MFMailComposeViewController* properties in your class, assign to them when creating, and check against them on result.

Something like:

@property (...) MFMailComposeViewController *mail1;
@property (...) MFMailComposeViewController *mail2;

self.mail1 = [[MFMailComposeViewController alloc] init];
...

 - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result2 error:(NSError *)error{
    if(controller == self.mail1) { ... }
}
于 2012-09-24T11:53:45.047 に答える