【发布时间】:2016-12-30 16:28:55
【问题描述】:
您好,我有一个 Json 文件:
{
"Name":"Car",
"Picture":"http://www.starpropertiesindia.com/blog/wp-content/uploads/2016/08/kochi1.jpg",
"Description":"Ford"
}
在 Table View Controller 中读取名称图片和描述。
我的 TableViewController 中有这段代码:
let name = aFruit["Name"].stringValue
let imageURL = aFruit["Picture"].stringValue
let description = aFruit["Description"].stringValue
现在我想将它们返回到表格视图单元格中。对于这种情况,我使用以下代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! TableViewCell
let fruit = fruits[indexPath.row]
cell.CellTitle.text = fruit.name
cell.CellDescription.text = fruit.description
cell.CellImage.image = fruit.imageURL
return cell
}
一切都适合
cell.CellTitle.text = fruit.name
和
cell.CellDescription.text = fruit.description
但是当我写的时候
cell.CellImage.image = fruit.imageURL
它给了我一个错误:
无法将 NSURL 类型的值赋给 UIimage 类型!
这里可能有什么错误?
【问题讨论】:
-
您的网络调用在哪里获取图像?
-
错误明确指出,.image 需要 UIImage 实例而不是 URL ... U 可以调用异步请求以延迟加载图像 ...
-
你能给我举个例子吗?我是初学者,我不明白