简体   繁体   English

在tableview单元格中从URL快速显示图像

[英]Swift show image from url in tableview cell

I am getting data from api and I want to show this data in tableview cell. 我正在从api获取数据,我想在tableview单元格中显示此数据。 I can show it but if there is a image link in it I can not show image. 我可以显示它,但是如果其中有图像链接,则无法显示图像。 (Just showing text) (仅显示文字)

my data like: "blablablabla http://image.com/testImage " 我的数据像:“ blablablabla http://image.com/testImage

I tried to split text and image but it is not a good solution. 我试图拆分文本和图像,但这不是一个好的解决方案。

How can I show data with image in swift? 如何快速显示带有图像的数据?

I think it will help you. 我认为它将为您提供帮助。

Just download custom classes of Haneke from here 只需从此处下载Haneke的自定义类

https://github.com/Haneke/HanekeSwift https://github.com/Haneke/HanekeSwift

And use given code where you want 并在需要的地方使用给定的代码

let URLString = self.items[indexPath.row]

let URL = NSURL(string:URLString)!

cell.imageView.hnk_setImageFromURL(URL)

If you want to do this without third party code you can load an image into a UIImageView using the imageWithData: method. 如果要在没有第三方代码的情况下执行此操作,则可以使用imageWithData:方法将图像加载到UIImageView As you're using a UITableView you need to do this asynchronously so as not to impact scrolling performance. 在使用UITableView您需要异步执行此操作,以免影响滚动性能。 You can do this with GCD by placing your image loading code in a dispatch_async block. 您可以通过将图像加载代码放在dispatch_async块中来使用GCD进行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM