gpt4 book ai didi

ios - 如何快速将图像添加到我的表格单元格?

转载 作者:搜寻专家 更新时间:2023-11-01 06:06:36 25 4
gpt4 key购买 nike

我正在关注 this tutorial我正在为每个 json 条目创建单元格。没有照片一切正常:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CELL")

if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL")
}

let user:JSON = JSON(self.items[indexPath.row])
// print(user)
let picURL = "/Users/K/Desktop/aproject/apps/address/addr/Images.xcassets/TabMap.imageset/up_dark.png"//just for tests - some random png
let url = NSURL(string: picURL)
let data = NSData(contentsOfURL: url!)

cell!.textLabel?.text = user["description"].string
// cell?.imageView?.image = UIImage(data: data!)

return cell!
}

,但是当我添加照片时(取消注释这一行):

cell?.imageView?.image = UIImage(data: data!)

然后我得到错误:

enter image description here

fatal error: unexpectedly found nil while unwrapping an Optional value

我的计划是传递一个 url 而不是硬编码的照片(因此使用 user["photo"] 而不是链接),但为了测试,我将 url 粘贴到我的自定义图片。

如何将它添加到文本旁边?

最佳答案

对于本 map 片:

cell!.imageView?.image = UIImage(named:"ImageName")

关于ios - 如何快速将图像添加到我的表格单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35531441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com