IOS Show image in textView inside tableViewCell

浪尽此生 提交于 2019-12-12 02:58:19

问题


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.

来源:https://stackoverflow.com/questions/30995408/ios-show-image-in-textview-inside-tableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!