【问题标题】:Push from a tableView to a MFMailComposerViewController从 tableView 推送到 MFMailComposerViewController
【发布时间】:2014-06-17 12:25:46
【问题描述】:

我目前正在开发一个应用程序,其中有一个包含 7 个部分的静态 tableView。这些部分是用户可以申请的不同课程,我想要完成的是当用户单击某个部分的行/按钮时。它推送一个MailComposerView 并在邮件中它说例如,

您好,我想申请课程 %@,该课程在该日期 %@ 累积。 %@ 是选定的课程和日期。

如果我需要添加更多信息/代码,请告诉我。

谢谢。

【问题讨论】:

  • 有什么问题?你想在点击 UITableViewCell 时显示邮件编辑器吗?
  • 是的,并且带有来自所选单元格的信息

标签: ios objective-c uitableview mfmailcomposeviewcontroller


【解决方案1】:

您需要使用 UITableView 的 didSelectRowAtIndexPath: 方法。试试下面的方法:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; 
    mailViewController.mailComposeDelegate = self;
    [mailViewController setSubject:@"Course Apply"]; //Set the subject here
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // this gets the currently selected cell.. Hope in your case, it's a custom cell. 
    [mailViewController setMessageBody:[NSString stringWithFormat:@"Hi I would like to apply to course %@ which accrues at this date %@",cell.courseSelected,cell.courseData] isHTML:NO]; //courseSelected and courseDate are properties that hold value in your custom cell
    NSArray *toRecipients = [NSArray arrayWithObject:@"your.email@email.com"];
    [mailViewController setToRecipients:toRecipients]; // set the recipient address here
    [self presentViewController:mailViewController animated:YES completion:nil]; // and finally present it... 
}

希望这会有所帮助..

【讨论】:

    【解决方案2】:

    <MessageUI/MessageUI.h><MessageUI/MFMailComposeViewController.h> 导入您的viewController 并将MFMailComposeViewControllerDelegate 添加到您的界面。

    使用此代码显示MailComposeView

    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    [mailViewController setSubject:@"<subject here>"]
    [mailViewController setMessageBody:@"" isHTML:NO];
    NSArray *toRecipients = [NSArray arrayWithObject:@"your.email@email.com"];
    [mailViewController setToRecipients:toRecipients];
    
    [self presentViewController:mailViewController animated:YES completion:nil];
    

    这将解雇MailComposeView

    -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        NSLog(@"ERROR: %@", error);
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    

    如果您想拥有不同的正文文本,请将代码放入接受NSString 参数的方法中,然后从按钮或行的选择方法中调用该方法,并为其提供您希望在正文中包含的文本。

    【讨论】:

    • 谢谢,我知道那部分,但我想我会用另一种方法,所以我结束了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多