我想从使用Alomofire和swiftyJSON的json加载图像。 JSON是字典:从alamofire swift在tableview单元格中加载图像
{"name": {"image": "https://...",}}
Alamorefire和SwiftyJSON
var imageLoad: String!
Alamofire.request(.GET, url).responseJSON { (response) -> Void in
if let value = response.result.value {
let json = JSON(value)
if let jsonDict = json.dictionary {
let image = jsonDict["name"]!["image"].stringValue
print(image) // https://....
self.imageLoad = image
}
self.tableView.reloadData()
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TVCell
// Configure the cell...
cell.imageTableView.image = UIImage(named: imageLoad) // not working "fatal error: unexpectedly found nil while unwrapping an Optional value"
如果有人可以帮助?如果有另一种方式随意写。
wouldnt这有可能创造一个比赛c ondition?如果单元格正在加载图像,则会被回收,并且第二次immage的加载速度会比第一次更快。 – Jeremie