簡體   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