0

我有一个 UIPickerViewDelegate,它允许用户从选择器中选择一个术语,并通过使用 NSDictionary 访问存储在 plist 文件中的数据来查看术语的定义。我还有一个 MFMailComposeViewController 允许用户通过电子邮件发送该术语及其在其他地方的定义。

但我似乎无法正确格式化术语和定义以输入电子邮件。我查看了各种“将 NSDictionary 转换为 NSString”的解决方案,但似乎都没有提供我需要的东西,包括Term = [dict objectForKey:@"Term"].

在 viewDidLoad 下,我有以下内容:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Glossary" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.termArray = [dict objectForKey:@"Term"];
self.definitionArray = [dict objectForKey:@"Definition"];

我的 pickerView 代码包括:

NSString *resultString = [[NSString alloc] initWithFormat:
                          @"%@",
                          [definitionArray objectAtIndex:row]];
definitionLabel.text = resultString;
NSString *termString = [[NSString alloc] initWithFormat:
                          @"%@",
                          [termArray objectAtIndex:row]];

showEmail 的代码包含:

int definitionIndex = [self.termPicker selectedRowInComponent:0];
NSString *emailTitle = [NSString stringWithFormat:@"Definition of %@", termLabel];
NSString *emailDefinition = [definitionArray objectAtIndex:definitionIndex];
NSString *messageBody = [NSString stringWithFormat:@"The definition of <B>%@</B> is:<P> <B>%@</B>", termLabel, emailDefinition];

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:YES];

我希望从选择器中选择的术语和与之关联的定义中提取电子邮件标题和消息正文。我确定这一定是一个简单的格式问题,但我无法弄清楚。

4

0 回答 0