gpt4 book ai didi

iOS下载图片、tableViewCell和Array

转载 作者:行者123 更新时间:2023-11-29 01:54:28 25 4
gpt4 key购买 nike

我有一个数组。在我的数组中有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com