gpt4 book ai didi

ios - 如何在 iOS 13.3 上使用 xib 显示 UITableViewCell?

转载 作者:行者123 更新时间:2023-11-29 05:13:55 25 4
gpt4 key购买 nike

如何使用 xib 显示单元格?在 iOS 13 之前的设备上,此方法会显示单元格,但自 iOS 13 起,它不会显示。SurveyFacultyCell.xib 自定义表格 View 单元格的名称

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

var cell:SurveyFacultyCell? = tblView.dequeueReusableCell(withIdentifier: "surveyFacultyCell") as? SurveyFacultyCell

if cell == nil {
tblView.register(UINib(nibName: "SurveyFacultyCell", bundle: nil), forCellReuseIdentifier: "surveyFacultyCell")
cell = tblView.dequeueReusableCell(withIdentifier: "surveyFacultyCell") as? SurveyFacultyCell
}
cell?.selectionStyle = .none
cell?.contentView.backgroundColor = UIColor.clear

let dictFaculty = arrFaculty[indexPath.row] as! NSDictionary

print(dictFaculty)

cell?.lblName.text = dictFaculty.string(forKey: "facultyName")
print(cell?.lblName.text as Any)
}

最佳答案

您注册 Xib 的方式错误。只需在 viewDidLoad() 处注册即可。我告诉你如何Xib 注册而不是你的逻辑

这是我的回答:

在 viewDidLoad() 上注册 xib

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

cellForRowAt:

let cell = tableView.dequeueReusableCell(withIdentifier: "surveyFacultyCell", for: indexPath) as! SurveyFacultyCell

... Your logic ...

return cell

完成

override func viewDidLoad() {
super.viewDidLoad()

tableView.delegate = self
tableView.dataSource = self

tableView.register(UINib(nibName: "SurveyFacultyCell", bundle: nil), forCellReuseIdentifier: "SurveyFacultyCell")
}


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

let cell = tableView.dequeueReusableCell(withIdentifier: "surveyFacultyCell", for: indexPath) as! SurveyFacultyCell

cell?.selectionStyle = .none
cell?.contentView.backgroundColor = UIColor.clear

let dictFaculty = arrFaculty[indexPath.row] as! NSDictionary

print(dictFaculty)

cell?.lblName.text = dictFaculty.string(forKey: "facultyName")
print(cell?.lblName.text as Any)
}

关于ios - 如何在 iOS 13.3 上使用 xib 显示 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59387219/

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