我正在尝试从 url 下载图像并使其成为 TableView 中每个单元格的 tableviewcell 图像。程序下载每个cell的内容,然后根据服务器传入的id值使用alamofire下载图片。
当我使用下面的代码时,第一张图像总是与第二张图像相同,我无法弄清楚为什么,当我添加更多单元格时,它们工作得很好。我今天才刚刚开始使用 alamofire,所以我可能遗漏了一些明显的东西,如果是这样,请提前道歉。
for result in resultsAsArray {
if let resultDict = result as? NSDictionary {
let cell = UITableViewCell(style: .Value1, reuseIdentifier: "identifer")
cell.textLabel?.text = resultDict.objectForKey("name") as? String
let id = (resultDict.objectForKey("productId") as! String).toInt()!
cell.tag = id
cell.imageView?.image = UIImage(named: "placeholder")
let image = request(.GET,
"http://www.website.com/\(id).png").response() {
(_, _, data, _) in
println("loading image for \(id)")
let image = UIImage(data: data! as NSData)
cell.imageView!.image = image
}
products.append(cell)
(view.viewWithTag(1) as! UITableView).reloadData()
}
}
最佳答案
我已经确定问题出在服务器端,当我更改图像时,它们不会立即在服务器上更改 - alamofire 工作正常
- 我最初将第一个单元格图像制作为数字 2 的图像,在我移动它之后,alamofire 缓存了它所以它始终显示用于数字 2 的图像
关于ios - alamofire,下载多张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31689218/