如何编辑 masterDetailView 模板以允许在 tableview 中自定义单元格
How to edit masterDetailView template to allow custom cells within tableview
我创建了一个名为 CustomeTableViewCell 的自定义 class,其中包含以下代码:
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
在我的主视图控制器中,下面显示了两位代码。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let coursework = fetchedResultsController.object(at: indexPath)
configureCell(cell, withCoursework: coursework)
return cell
}
func configureCell(_ cell: UITableViewCell, withCoursework coursework: Coursework) {
cell.textLabel?.text = databaseTest.name
}
我的问题是如何编辑这段代码以允许在 cofigureCell 中使用多个标签。所以函数看起来像这样:
func configureCell(_ cell: UITableViewCell, withCoursework coursework: Coursework) {
cell.label1.text = databaseTest.name
cell.label2.text = databaseTest.surname
}
我对 swift 编码还很陌生,因此欢迎任何反馈。
当您将单元格出队时,您应该将它们转换为 CustomeTableViewCell。
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomeTableViewCell
然后通过更改函数中的单元格类型,您将能够设置所有标签。
func configureCell(_ cell: CustomeTableViewCell, withCoursework coursework: Coursework) {
我创建了一个名为 CustomeTableViewCell 的自定义 class,其中包含以下代码:
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
在我的主视图控制器中,下面显示了两位代码。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let coursework = fetchedResultsController.object(at: indexPath)
configureCell(cell, withCoursework: coursework)
return cell
}
func configureCell(_ cell: UITableViewCell, withCoursework coursework: Coursework) {
cell.textLabel?.text = databaseTest.name
}
我的问题是如何编辑这段代码以允许在 cofigureCell 中使用多个标签。所以函数看起来像这样:
func configureCell(_ cell: UITableViewCell, withCoursework coursework: Coursework) {
cell.label1.text = databaseTest.name
cell.label2.text = databaseTest.surname
}
我对 swift 编码还很陌生,因此欢迎任何反馈。
当您将单元格出队时,您应该将它们转换为 CustomeTableViewCell。
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomeTableViewCell
然后通过更改函数中的单元格类型,您将能够设置所有标签。
func configureCell(_ cell: CustomeTableViewCell, withCoursework coursework: Coursework) {