繁体   English   中英

尤里卡的自定义行

[英]Custom Row in Eureka

我正在尝试创建一个显示图像的自定义行。 因此,我首先尝试了Eureka页面中指示的基本自定义行: https : //github.com/xmartlabs/Eureka#basic-custom-rows

这是我正在使用的代码:

import Eureka

    public class CustomCell2: Cell<Bool>, CellType{
        @IBOutlet weak var switchControl: UISwitch!
        @IBOutlet weak var label: UILabel!

        public override func setup() {
            super.setup()
            switchControl.addTarget(self, action: #selector(CustomCell2.switchValueChanged), forControlEvents: .ValueChanged)
        }

        func switchValueChanged(){
            row.value = switchControl.on
            row.updateCell() // Re-draws the cell which calls 'update' bellow
        }

        public override func update() {
            super.update()
            backgroundColor = (row.value ?? false) ? .whiteColor() : .blackColor()
        }
    }
    public final class CustomRow: Row<Bool, CustomCell2>, RowType {
        required public init(tag: String?) {
            super.init(tag: tag)
            // We set the cellProvider to load the .xib corresponding to our cell
            cellProvider = CellProvider<CustomCell2>(nibName: "CustomCell2")
        }
    }

并将其保存为CustomCell2.swift。 我使用此调用该自定义行: futurSection <<< CustomRow ("")

但是我遇到一个错误: Could not load NIB in bundle with name 'CustomCell2'

而且,如何将其更改为UIImage?

您好,我一直在审查您的问题,这是我的结果

我使用您的代码并进行一些修改,这是我的EurekaCustomImageCell.swift

import UIKit
import Eureka

public class CustomCell2: Cell<Bool>, CellType{


    @IBOutlet weak var customImage: UIImageView!
    public override func setup() {
        super.setup()
    }

    public override func update() {
        super.update()
        backgroundColor = (row.value ?? false) ? .whiteColor() : .blackColor()
    }
}
public final class CustomRow: Row<Bool, CustomCell2>, RowType {
    required public init(tag: String?) {
        super.init(tag: tag)
        // We set the cellProvider to load the .xib corresponding to our cell
        cellProvider = CellProvider<CustomCell2>(nibName: "CustomCell2")
    }
}

如您所见,这里是一个@IBOutlet weak var customImage: UIImageView! 这是我的xib文件中为此定制单元定义的插座,请检查此图像

在此处输入图片说明

希望这对您有帮助,对我没有问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM