2017-03-09 62 views
0

我遇到了一些麻烦。看看代码波纹管的这一部分:dataTask错误 - “无法用类型参数列表调用'dataTask'”

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

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

+2

尝试改变'(数据:NSData的?,响应:URLResponse ?,错误:错误)''到数据,响应,错误'。 – OOPer

+0

@OOPer好吧,所以这里是更新后的代码let dataTask = session.dataTask(with:request,completionHandler:{(data,response,error)现在我得到一个错误 - 对成员dataTask的模糊引用(with:completionHandler) ' – iFunnyVlogger

+1

@iFunnyVlogger你需要使用'URLRequest'而不是'NSURLRequest' –

回答

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

      }) 
相关问题