【问题标题】:Asynchronously load images from document directory into UITableView将文档目录中的图像异步加载到 UITableView
【发布时间】:2015-01-07 16:08:34
【问题描述】:

我有 UITableView,我需要从文档目录中列出我保存的图像,我使用代码 NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES ); NSString *docDirectory = [sysPaths objectAtIndex:0]; dispatch_queue_t queue_=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue_, ^{ NSString *filePath=[docDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"MyFolder_New/%@",[[[tableArray objectAtIndex:indexPath.row] componentsSeparatedByString:@"/"] lastObject]]]; dispatch_async(dispatch_get_main_queue(), ^{ [img setImage:[UIImage imageWithData:[NSData dataWithContentsOfFile:filePath]]]; [indicator stopAnimating]; }); }); 将图像异步显示到 UITableView 但 UITableView 在滚动到顶部和底部时滞后。

【问题讨论】:

    标签: objective-c uitableview nsdocumentdirectory


    【解决方案1】:

    在返回之前自定义单元格时,您需要在方法 tableView:cellForRowAtIndexPath: 中使用 dispatch_asynch。 脚步: 1. 从池中获取单元格。 2.定制它。 3. 启动dispatch_asynch,什么会设置正确的图像(这需要检查单元格是否仍然相同)到单元格。

    我们一直都在这样做,我们从不滞后。但是图像会延迟出现在单元格中(这是正确的)。试试看。

    【讨论】:

      猜你喜欢
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 2012-03-31
      • 2012-09-04
      • 2012-01-27
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      相关资源
      最近更新 更多