我实现了下面的代码,并记录了arrayPlainText
,但是当我在模拟器和iPhone上运行它时,它只显示第一个项目,其他一切都消失了。
NSMutableArray *xmlListContent;
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:[self returnListPath]])
{
xmlListContent = [[NSMutableArray alloc] initWithContentsOfFile:[self returnListPath]];
NSMutableArray *listContent = [[NSMutableArray alloc] init];
int i;
for(i = 0; i < [xmlListContent count]; i++)
{
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setSubject:editedListTitle];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
NSString *item = [NSString stringWithString:[[xmlListContent objectAtIndex:i] objectForKey:@"label"]];
NSString *tempString = [NSString stringWithFormat:@"-%@",item];
[listContent addObject:tempString];
NSString *arrayPlainText = [listContent componentsJoinedByString:@"<br>"];
[mailComposer setMessageBody:[NSString stringWithFormat:@"<html>%@</html>",arrayPlainText] isHTML:YES];
DLog(arrayPlainText);
[self presentModalViewController:mailComposer animated:YES];
}
}
}
else
{
xmlListContent = [NSMutableArray array];
DLog(@"failed to compose list via email");
}
答案 0 :(得分:1)
答案就在这里。
NSMutableArray *xmlListContent;
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:[self returnListPath]])
{
xmlListContent = [[NSMutableArray alloc] initWithContentsOfFile:[self returnListPath]];
NSMutableArray *listContent = [[NSMutableArray alloc] init];
int i;
for(i = 0; i < [xmlListContent count]; i++)
{
NSString *item = [[xmlListContent objectAtIndex:i] objectForKey:@"label"];
NSString *tempString = [NSString stringWithFormat:@"-%@", item];
[listContent addObject:tempString];
}
NSString *arrayPlainText = [listContent componentsJoinedByString:@"<br>\n"];
DLog(arrayPlainText);
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
[mailComposer setSubject:editedListTitle];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[mailComposer setMessageBody:[NSString stringWithFormat:@"<html>%@</html>",arrayPlainText] isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
}
else
{
xmlListContent = [NSMutableArray array];
DLog(@"failed to compose list via email");
}
}
答案 1 :(得分:0)
这段代码怎么样:
NSString *item = [NSString stringWithString:[[self.array objectAtIndex:i] objectForKey:@"label"]];
NSString *tempString = [NSString stringWithFormat:@"-%@",item];
[listContent addObject:tempString];
NSString *arrayPlainText = [listContent componentsJoinedByString:@"<br>"];
[mailComposer setMessageBody:[NSString stringWithFormat:@"<html>%@</html>",arrayPlainText] isHTML:YES];
DLog(arrayPlainText);