2017-03-09 83 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!) 

      }) 
相關問題