我想從使用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