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

标签 ios swift uitableview

有人知道如何填写两个不同的单元格吗? 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/

相关文章:

ios - 保存从 XCUIScreenshot 函数捕获的屏幕截图

ios - 使用背景图像自定义 Parse 登录 (Swift)

swift - 核心数据 - 如何从实体属性中获取最大值(Swift)

swift - 使用添加的属性创建 UIImage 的子类

ios - 保存在 TableView 中生成的随机数

ios - 在 UITableView 中获取 JsonData

android - 在外部应用程序(facebook、twitter 或浏览器)中打开来自 Cordova 应用程序的链接,适用于 iOS 和 Android

ios - 当我点击单元格时如何执行特定的工作?

swift - 如何在 swift UI 中扫描和读取二维码

ios - 根据 UISwitch 状态在我的主 ScrollView 上添加更多 tableView 作为 subview 仅在应用程序重新启动后才起作用