尤里卡的自定义行

时间:2016-07-04 15:50:38

标签: ios swift eureka-forms

我正在尝试创建一个显示图片的自定义行。所以我首先尝试了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?

1 个答案:

答案 0 :(得分:4)

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

我使用您的代码并进行一些修改,这是我的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文件中为此自定义单元格定义的插座,请查看此图片

https://location.services.mozilla.com/v1/geolocate?key=test

我希望这可以帮助你,这对我没有问题