IOS Show image in textView inside tableViewCell

2019-09-10 19:26发布

问题:

I got 2 images from document folder.

I used this code to get 2 images from document folder:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *myPath = [paths objectAtIndex:0];      
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:myPath error:nil];
NSMutableArray *subpredicates = [NSMutableArray array];
[subpredicates addObject:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.png'"]];
[subpredicates addObject:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.jpg'"]];
NSPredicate *filter = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];

NSArray *onlyImages = [directoryContents filteredArrayUsingPredicate:filter];

I got 2 images in array: onlyImages.

I used this code to set images in UIImageView inside TableViewCell.

for (int i = 0; i < onlyImages.count; i++) {
    NSString *imagePath = [myPath stringByAppendingPathComponent:[onlyImages objectAtIndex:i]];
    UIImage *tempImage = [UIImage imageWithContentsOfFile:imagePath];
    [self.imgViewInTextView setImage:tempImage];
}

But, is only show 1 image in last cell.

Here is image demo.