如何在NSDocumentDirectory中添加更多图像?

时间:2013-11-22 11:08:38

标签: ios iphone objective-c

首先,我将来自Web服务的图像路径存储到SQLITE中,然后使用本地路径将其检索回来。我正在使用NSMutableArray。我已成功将一个图像存储在NSDocumentDirectory中,但我有一个问题,如何在NSDocumentDirectory中存储多个图像?

我的代码是,

if ([[[node childAtIndex:counter] name] isEqualToString:@"Column5"])
        {
            NSString *str = [[node childAtIndex:counter] stringValue];

            [Col5 addObject:str];

            NSString *myString = [Col5 componentsJoinedByString:@","];

            NSString *aString = [NSString stringWithFormat:@"http://webserviceurl/%@",myString];

            NSURL *url= [NSURL URLWithString:aString];

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

            NSString *documentsDirectory = [paths objectAtIndex:0];

            NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:strCol4];

            UIImage *image = tmpImage;

            NSData *imageData = UIImagePNGRepresentation(image);

            [imageData writeToFile:savedImagePath atomically:NO];
        }

1 个答案:

答案 0 :(得分:2)

对于这一行:

NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:strCol4];

只需使用其他路径组件。