【发布时间】:2018-10-30 15:30:06
【问题描述】:
我正在使用 AlamofireImages 尝试从服务器下载图像并将其显示在我的表格视图单元格中,这是我得到的,但我的图像没有出现,只有 textLabel 和 detailTextLabel
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "trendingCell", for: indexPath)
print(self.array[indexPath.row])
cell.textLabel?.text = (self.array[indexPath.row]["title"] as! String)
cell.detailTextLabel?.text = (self.array[indexPath.row]["username"] as! String)
Alamofire.request("http://xxxxxxx.com/uploads/" + (self.array[indexPath.row]["cover"] as! String)).responseImage { response in
if let image = response.result.value {
cell.imageView?.image = image
}
}
return cell
}
【问题讨论】:
-
是否调用了
cell.imageView?.image = image?您在控制台中有任何错误日志吗?cell.imageView不为零吗? -
您是否通过在完成块中提供
print(response)来检查您的response是否有效? -
能否验证图片url是否有效且请求成功。围绕此功能添加一些额外的日志记录,检查响应是否有效等
-
这可能看起来很傻,但尝试删除圆角半径,如果您已将任何背景颜色设置为默认值,请删除任何图层操作(如阴影),尝试将剪辑切换到边界,我有同样的问题但是不记得确切的解决方案我做了什么,但我做了上述之一
-
尝试任何静态图像作为占位符并检查它是否正确显示,或者用户 alamofire 的 imageview 的扩展名
imageView.af_setImage(并打印response
标签: ios swift uitableview alamofire alamofireimage