swift - dataTask 错误 - "Cannot invoke ' dataTask',其参数列表类型为...”

标签 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

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

最佳答案

根据一些评论,我有了答案!我将“请求”从 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/

相关文章:

ios - NSOperation 取消和 NSOperationQueue

swift - 两个框架使用一个属性的名称

ios - Xcode 11.2 场景编辑器是否允许添加组件?

ios - Xcode 4.2 是否兼容 OS4 和 iOS5?

ios - 返回 UITableViewCell 自定义单元格

ios - 如何在每几个 TableView 单元格之间添加条形图

swift - 我正在尝试检测 ARKit SceneKit 中两个节点之间的接触

swift - 快速 REPL 中的 LLDB GUI

iphone - 用于构建通用应用程序的最新资源/教程?

ios - 如何检查 UITableView 何时完成滚动