gpt4 book ai didi

ios - 如何填写2个不同的单元格?

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

有人知道如何填写两个不同的单元格吗? enter image description here

对于每个单元格,我都有特定的类别

import UIKit

class MindCell: UITableViewCell {

@IBOutlet var textLabel1: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}

class StepsMind: UITableViewCell {

@IBOutlet var number1Label: UILabel!
@IBOutlet var step1Label: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}

但我不知道如何设置功能

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

let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MindCell

// Configure the cell...
cell.textLabel1.text = "ABC"

return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier1 = "MindCell"
let cell1 = tableView.dequeueReusableCell(withIdentifier: cellIdentifier1, for: indexPath) as! StepsMind

// Configure the cell...
cell1.number1Label.text = "1"
cell1.step1Label.text = "DEF"

return cell1
}

Xcode 表示不可能同时使用 2 个这些功能。我需要做什么?

最佳答案

通过查看评论,我假设您需要备用行类型。

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

if indexPath.row % 2 == 0
{
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MindCell

// Configure the cell...
cell.textLabel1.text = "ABC"

return cell
}
else
{
let cellIdentifier1 = "MindCell"
let cell1 = tableView.dequeueReusableCell(withIdentifier: cellIdentifier1, for: indexPath) as! StepsMind

// Configure the cell...
cell1.number1Label.text = "1"
cell1.step1Label.text = "DEF"

return cell1

}

}

关于ios - 如何填写2个不同的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42368672/

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