从文档目录中提取图像时,图像是重复的

时间:2016-09-10 11:07:14

标签: ios

我正在使用scrollview进行图片加载。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
dataPath = [documentsDirectory stringByAppendingPathComponent:@"/Images"];


if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];

NSArray *docsArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:&error];
for (int i = 0; i < [docsArray count]; i++)
{
    NSString *strPath = [docsArray objectAtIndex:i];
    if([strPath containsString:[NSString stringWithFormat:@"%@_",strID]])
    {
        [imgArray addObject:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",dataPath,strPath]]];
        NSLog(@"%@%@",dataPath,strPath);
    }

}
if([imgArray count]>0)
    [self showImages];

0 个答案:

没有答案