我有一个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];
我希望电子邮件标题和邮件正文从选择器中选择的术语和与之关联的定义中拉出。我确定它必须是一个简单的格式化问题,但我无法弄明白。