0

我有一个希望得到帮助的问题,我让最初的邮件编辑器加载并正常工作,但我想知道是否可以说添加多个按钮可以调出邮件编辑器,我就是在我的应用程序中尝试做的是让用户能够通过附件将文件通过电子邮件发送给自己,但是有没有一种方法可以拥有多个按钮,当单击它时,邮件编写器将提供该文件。我希望这是有道理的,提前感谢任何提供帮助的人

这是在我的 .h 文件中

- (IBAction)Email:(id)sender;

这是在我的 .m 文件中

- (IBAction)Email:(id)sender
{
    if ([MFMailComposeViewController canSendMail]) 
        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];

    mail.mailComposeDelegate = self;
    [mail setSubject:@"Questions or Concerns"];

    NSArray *recipient = [NSArray arrayWithObjects:@"abc@yahoo.com", nil];
    [mail setToRecipients:recipient];

    NSString *body = @"Please Send Your Feedback or any Suggestoins";
    [mail setMessageBody:body isHTML:NO];

    [self presentViewController:mail animated:YES completion:Nil];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
4

1 回答 1

0

你有很多选择让我们采取以下 senario 你有 2 个按钮 but1 (tag=1, attachment is file1) but2 (tag=2, attachment is file2) 你应该将两个按钮连接到相同的方法

- (IBAction)Email:(id)sender;

在 .m 文件中

- (IBAction)Email:(id)sender
{
    if ([MFMailComposeViewController canSendMail]) 
        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];

    mail.mailComposeDelegate = self;
    [mail setSubject:@"Questions or Concerns"];
 if (((UIButton *)sender).tag==1){
            // add file 1
    }
    else   if (((UIButton *)sender).tag==2){
            // add file 2 
    }
    NSArray *recipient = [NSArray arrayWithObjects:@"abc@yahoo.com", nil];
    [mail setToRecipients:recipient];

    NSString *body = @"Please Send Your Feedback or any Suggestoins";
    [mail setMessageBody:body isHTML:NO];

    [self presentViewController:mail animated:YES completion:Nil];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
于 2013-02-12T08:30:46.520 回答