【问题标题】:Custom Row in Eureka尤里卡中的自定​​义行
【发布时间】:2016-07-04 15:50:38
【问题描述】:

我正在尝试创建一个显示图像的自定义行。因此,我首先尝试了 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 &lt;&lt;&lt; CustomRow ("")

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

还有,如何将其更改为 UIImage?

【问题讨论】:

  • 你定义了 CustomCell2 笔尖?
  • 我想我没有那个。我不知道该怎么做。
  • 好的,我会检查并发布任何结果,问候
  • 嘿@JaysonTamayo,我希望你解决了你的问题,如果你没有,这可能会有所帮助blog.xmartlabs.com/2016/09/06/Eureka-custom-row-tutorial

标签: ios swift eureka-forms


【解决方案1】:

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

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

我希望这对你有帮助,这对我来说没有问题

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 1970-01-01
    • 2017-03-26
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2017-09-23
    • 1970-01-01
    相关资源
    最近更新 更多