gpt4 book ai didi

ios - SIGVART 与单元 View 与标签

转载 作者:行者123 更新时间:2023-11-30 11:37:25 25 4
gpt4 key购买 nike

我想知道为什么我在这段代码上收到 SIGBART 错误。我已经为每个图像和按钮分配了一个标签,但仍然收到错误。有谁知道为什么会这样?

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "Cat") as UITableViewCell!

let image = cell?.viewWithTag(1) as! UIImageView //the error is here
image.image = UIImage(named: "CatIcon")

let button = cell?.viewWithTag(2) as! UIButton
button.setTitle("Cat: \(CatView.catsnum[indexPath.row])", for: .normal)
button.titleLabel?.font = UIFont(name: Font, size: 20)
button.setTitleColor(.white, for: .normal)
button.addTarget(self, action: #selector(CatLink), for: .touchUpInside)
button.backgroundColor = .black
button.backgroundColor?.withAlphaComponent(0.5)

return cell!
}

最佳答案

您必须向单元格注册tableView

tableView.register(customClassName.self, forCellReuseIdentifier: "Cat")

或者用 xib 来实现

tableView.register(UINib(nibName: "customClassName", bundle: nil), forCellReuseIdentifier:"Cat")

关于ios - SIGVART 与单元 View 与标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49599858/

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