ios - Label.text 为零
问题描述
我正在尝试显示userNameLabel
内容“aaaaaaaaaaaaaaaaA”,userNameLabel
但是nil
.
class ChooseMemberTableViewCell: UITableViewCell, Reusable {
@IBOutlet weak var userImageView: UIImageView!
@IBOutlet weak var userNameLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
func setupCell(data: User) {
userNameLabel?.text = "aaaaaaaaaaaaaaaaA"
// userNameLabel?.text = "\(data.userName)"
// let url = URL(string: data.image)
// userImageView.sd_setImage(with: url ?? "", completed: nil)
}
}
评论中的附加代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = listContacts.dequeueReusableCell(for: indexPath, cellType: ChooseMemberTableViewCell.self).then {
let user = searchUser[indexPath.row]
$0.setupCell(data: user)
}
return cell
}
解决方案
有同样的问题。就我而言,问题在于单元注册方法。我正在使用register(_ cellClass: AnyClass?, forCellReuseIdentifier identifier: String)
,但这不起作用,因为我的单元格是在 xib 中创建的。使用register(_ nib: UINib?, forCellReuseIdentifier identifier: String)
帮助了我。
推荐阅读
- wordpress - 如何在 Wordpress 中查看以后是否有帖子?
- c - STM32L0 上的 VREF 输出
- javascript - 为什么我的代码在性能测试良好时滞后?
- jenkins - 在 GKE 上安装 Jenkins-X
- angular - 从对象自动填充 - Typescript/Angular 5
- python - 读取和写入标记化和 pos_tagged 单词到新文件
- c# - 从 c 中的列表中获取最高值
- nginx - 如何为 Github 身份验证配置 nginx-ingress 控制器?
- python - 如何创建关于年龄与时间的 np 数组随机数据?
- vue.js - 无法设置使用 beforeRouteEnter 钩子获取的数据 - vuesj2