iOS下载图片、tableViewCell和Array

标签 ios objective-c uitableview uiimageview

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

相关文章:

ios - 使用单个文件播放器音频单元播放多个文件

iphone - 删除 subview 时,从父 View 中删除

ios - 我可以直接从具有特定大小类或特征集合的 xib 加载 UITableViewCell 吗?

ios - 项目列表与数据源

objective-c - Objective-C : How to create custom/static table view cells via code

ios - 自定义 TableViewController 在 Swift 3 中播放声音和崩溃

objective-c - 如何从远程服务器在 iOS 中加载不同的图像

ios - 缩小结合注释

ios - 如何快速对字典中的 TableView 项目进行分组?

objective-c - 如何获取保存到 Core Data 托管对象上下文的对象的 ID?