我有一个数组。 在我的数组中有 8 个对象序列化:
- text
- text
- link Url Image.
- link Url Image.
- text
- link Url Image.
- link Url Image.
- text
我已经下载了所有图像并保存到文件夹中。 现在,如何从文档文件夹中获取所有图像并在 tableViewCell 中显示同一个 myArray?
我使用此代码从文档文件夹中获取所有图像。
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];
[_arrMessageFree addObject:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.png'"]];
[_ar addObject:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.jpg'"]];
NSPredicate *filter = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];
NSArray *onlyImages = [directoryContents filteredArrayUsingPredicate:filter];
但是,我无法在 myArray 中同时显示序列化的文本和图像。
最佳答案
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//after cell initialization add following code
for (UIView *subview in [cell.contentView subviews])
{
[subview removeFromSuperview];
}
UIImage *img=[UIImage imageWithContentsOfFile:[onlyImages objectAtIndex:indextPath.row]];
[cell.contentView addSubview:img];
}
关于iOS下载图片、tableViewCell和Array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31040647/