gpt4 book ai didi

ios - 如何以编程方式在 TableView 的静态单元格中添加图像

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:45 24 4
gpt4 key购买 nike

我在其中一个 ImageView 中添加了一个 ImageView 。我可以使用属性检查器然后更改图像属性,但我想以编程方式进行。

enter image description here

到目前为止,这就是我所做的并得到以下错误

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier account_cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell:UITableViewCell! = UITableViewCell()


if indexPath.section == 0{

if indexPath.row == 0{
cell = tableView.dequeueReusableCellWithIdentifier("account_cell", forIndexPath: indexPath)

if let AccountImage = cell.viewWithTag(100) as? UIImageView{
AccountImage.image = UIImage(named: "Friend_g")?.imageWithRenderingMode(.AlwaysOriginal)
}



}
}
print("\(indexPath)")
return cell
}

有人可以给我一个初学者指南,我如何以编程方式实现它。任何帮助将不胜感激。提前致谢。

最佳答案

您不需要使用 cellForRowAtIndexPath 在您的单元格中分配图像,因为您的单元格是静态的。

将图像分配到静态单元格的一种简单方法是通过这种方式创建 imageViewIBOutlet:

@IBOutlet weak var UserImage: UIImageView!

之后,在您的 viewDidLoad 方法中以这种方式将图像分配给 UserImage:

override func viewDidLoad() {

UserImage.image = UIImage(named: "Friends_g")
self.tableView.separatorColor = UIColor.clearColor()
}

结果将是:

enter image description here

关于ios - 如何以编程方式在 TableView 的静态单元格中添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34848535/

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