延迟加载UITableView与每个单元格中的多个图像
我正在使用延迟加载在一个表视图上显示图像。 但是我需要在每个单元格中创build一个包含多个图像的tableview,其中可以滚动。 所有图像只从服务器加载如何创build这个没有任何落后的表滚动? 有没有任何教程可用于此
试试这个代码。 SDWebImage 。 它从服务器下载映像并将其保存到设备caching。 另外,如果你不想保存它caching,那么你可能会看看AFNetworking
。
还有另一种select。 使用GCD (Grand Central Dispatch)
。
示例代码:
// Get the filename to load. NSString *imageFilename = [imageArray objectAtIndex:[indexPath row]]; NSString *imagePath = [imageFolder stringByAppendingPathComponent:imageFilename]; [[cell textLabel] setText:imageFilename]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(queue, ^{ UIImage *image = [UIImage imageWithContentsOfFile:imagePath]; dispatch_sync(dispatch_get_main_queue(), ^{ [[cell imageView] setImage:image]; [cell setNeedsLayout]; }); });
使用相同的显示多个图像。 使用这个将会增加加载tableview的性能。
请参阅GCD
以了解有关GCD
更多信息
试试这个https://github.com/nicklockwood/AsyncImageView 。易于从服务器asynchronous下载图像。