使用tableview或NSmutableDictionary中的材料发送电子邮件

时间:2015-04-14 23:19:04

标签: ios email nsdictionary

在我的应用程序中,我有一个tableView,其材料来自我的NSmutableDictionary。当我按下按钮时,我想将这些材料发送到电子邮件。这是发送电子邮件的代码:

//Below to send email
- (IBAction)showEmail:(id)sender {
    // Email Subject
    NSString *emailTitle = @"Course Planner of iBcChem";
    // Email Content
    NSString *messageBody = @"Please check my course plan";
    // To address
    NSArray *toRecipents = [NSArray arrayWithObject:@"xxxxx@gmail.com"];

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
    [mc setSubject:emailTitle];
    [mc setMessageBody:messageBody isHTML:NO];//want to fix here
    [mc setToRecipients:toRecipents];

    // Present mail view controller on screen
    [self presentViewController:mc animated:YES completion:NULL];

}

这是我的问题:

如何将材料添加到messageBody?我可以在我的messageBody中使用类似于显示我的字典的方法吗?

NSLog(@"Dictionary: %@", [_sectionContents description]);//test dictionary here

_sectionContents是我的字典。

1 个答案:

答案 0 :(得分:1)

您可以使用您编写的相同代码附加字典。

这是给你的代码。

NSString *emailTitle = @"Course Planner of iBcChem";
NSString *messageBody = @"Please check my course plan";
NSDictionary *dci = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"1",@"2", nil] forKeys:[NSArray arrayWithObjects:@"A",@"B", nil]];
NSArray *toRecipents = [NSArray arrayWithObject:@"xxxxx@gmail.com"];

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


mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:dci.description isHTML:NO];
[mc setToRecipients:toRecipents];

[self presentViewController:mc animated:YES completion:NULL];

在模拟器邮件委托中需要一些时间来加载mailcomposersheet的Body部分。身体看起来像。

{
    A = 1;
    B = 2;
}

享受编码!!