我正在尝试优化应用程序中的负载,事实上,我的应用程序中加载了很多图像,并且我花了很多时间等待视图控制器打开,特别是第一个初始视图,其中包含很多图像的图像。
我看了一下苹果样品 https://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
但我无法重新编写整个应用程序,我想要的只是具体告诉我我应该做什么?我实施?
in the tableview
,单元的实现位置cellforrowatindexpath:
NSURL *imageURL = ......;
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *imageLoad;
imageLoad = [[UIImage alloc] initWithData:imageData];
imageView.image = imageLoad;
我可以做点什么吗?
感谢您的帮助!
试试这个代码:
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(q, ^{
/* Fetch the image from the server... */
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
/* This is the main thread again, where we set the tableView's image to
be what we just fetched. */
cell.imgview.image = img;
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)