ios - alamofire,下载多张图片

标签 ios swift alamofire

我正在尝试从 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/

相关文章:

ios - 如何将图像加载到 iOS 应用程序中

iOS:自定义相机如何始终以正确的方向保存图像?

iphone - 移动 safari 中忽略的溢出 x 值

ios - ReplayKit stopRecording 不是第一次进入

Swift : JSONSerialization. jsonObject 无法将 json 转换为 json

json - 无法使用 Alamofire 从 Rest api 选择 json 数组

ios - 从 UITabBarController 初始化 viewController

swift - Xcode 模拟器 - 复制/粘贴问题

ios - 如何继续检查我的 Swift 应用程序是否有互联网连接?

ssl - Alamofire 测试包括自签名证书?