我在通过 AlamofireImage 加载图像时遇到问题,如何在加载图像后更新单元格?或者我必须在 tableviewcell.swift 中提出请求
我的表视图控制器
class NewTableViewController: UITableViewController {
var videos = [Video](){
didSet {
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
}
let URL = "https://api.vid.me/channel/1/new"
override func viewDidLoad() {
super.viewDidLoad()
let request = Alamofire.request(.GET, self.URL)
request.responseObject { (response: Response<NewestVideos, NSError>) in
switch response.result {
case .Success(let newest):
self.videos = newest.videos!
print(self.videos)
case .Failure(let error):
print("Request failed with error: \(error)")
}
}
}
...
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! VideoTableViewCell
let video = videos[indexPath.row]
cell.titleLabel?.text = video.title != nil ? video.title! : "no name"
cell.videoImageView?.af_setImageWithURL(NSURL(fileURLWithPath: video.thumbnailUrl!)) //here i make image request from url (and url i get from request in viewdidload)
return cell
}
...
}