0

我实现了下面的代码,并记录了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");
    }
4

2 回答 2

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");
    }
}
于 2012-10-28T07:59:55.183 回答
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);
于 2012-10-27T15:26:55.433 回答