我遇到了一些麻烦。查看下面的这部分代码:
// Create a datatask and pass in the request
let dataTask = session.dataTask(with: request, completionHandler: { (data:NSData?, response:URLResponse?, error:Error?) in
// Get a reference to the image view element of the cell
let imageView = cell.viewWithTag(1) as! UIImageView
// Create an image onject from the data and assign it into the ImageView
imageView.image = UIImage(data: data!)
})
我该如何解决这个问题?提前致谢!
最佳答案
根据一些评论,我有了答案!我将“请求”从 NSURLRequest 更改为 URLRequest,并将代码更新为:
// Create a datatask and pass in the request
let dataTask = session.dataTask(with: request, completionHandler: { (data, response, error) in
// Get a reference to the image view element of the cell
let imageView = cell.viewWithTag(1) as! UIImageView
// Create an image onject from the data and assign it into the ImageView
imageView.image = UIImage(data: data!)
})
关于swift - dataTask 错误 - "Cannot invoke ' dataTask',其参数列表类型为...”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42706622/