简体   繁体   中英

How can I add more images in NSDocumentDirectory?

First I stored image path from web service into SQLITE, and then I retrieve it back using local path. I am using NSMutableArray. I've successfully stored one image in NSDocumentDirectory, but I have one issue, How can I store more than one images in NSDocumentDirectory?

My code is,

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];
        }

For this line:

NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:strCol4];

Just use a different path component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM