简体   繁体   中英

Swift show image from url in tableview cell

I am getting data from api and I want to show this data in tableview cell. 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 "

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

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. As you're using a UITableView you need to do this asynchronously so as not to impact scrolling performance. You can do this with GCD by placing your image loading code in a dispatch_async block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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