dataTask出错 - "无法调用' dataTask'使用类型的参数列表..."

时间:2017-03-09 22:21:31

标签: swift xcode uitableview

我遇到了麻烦。查看以下代码部分:

// 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!)

            })

我在第二行收到错误,这是错误:enter image description here

我该如何解决这个问题?提前谢谢!

1 个答案:

答案 0 :(得分:0)

由于一些评论,我有一个答案!我更改了"请求"从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!)

            })