尝试从firebase数据库到tableview的show image [英] Trying show image from firebase database to tableview

查看:104
本文介绍了尝试从firebase数据库到tableview的show image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从firebase数据库到tableview的show image但是收到错误。

I am Trying show image from firebase database to tableview but getting error.


对成员'dataTask的不明确引用(with:completionHandler: )'

Ambiguous reference to member 'dataTask(with:completionHandler:)'



let url = NSURL(string: profileImageUrl)
let session = URLSession.shared
let task = session.dataTask(with: url) { (data, response, err) in
    if err != nil {
       return
    }
    cell.imageView?.image = UIImage(data: data)
}          
task.resume()


推荐答案

从swift 3版本开始,Swift标准库包含没有'NS'前缀的Foundation框架类;因此,由于您使用的是URLSession而不是NSURLSession,因此必须使用URL而不是NSURL使两个类在URLSession实例方法'dataTask(with:completionHandler :)中'相互兼容。

as from swift 3 version , Swift Standard Library includes Foundation framework classes without 'NS' prefix; so since you are using URLSession instead of NSURLSession, you must use URL instead of NSURL to make both classes compatible with each other in URLSession instance method 'dataTask(with:completionHandler:)'.

只需将url声明为

let url = URL(string: profileImageUrl)

已完成。

这篇关于尝试从firebase数据库到tableview的show image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆