尤里卡的自定义行 [英] Custom Row in Eureka

查看:180
本文介绍了尤里卡的自定义行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个显示图像的自定义行。所以我开始尝试在Eureka页面中指出的基本自定义行:



我希望这会对你有所帮助,这对我有用而没有问题


I am trying to create a custom row that shows an image. So I started by trying the basic custom row indicated in Eureka's page: https://github.com/xmartlabs/Eureka#basic-custom-rows

Here's the code I am using:

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")
        }
    }

And that is saved as CustomCell2.swift. I am calling that custom row using this: futurSection <<< CustomRow ("")

But I am getting an error: Could not load NIB in bundle with name 'CustomCell2'

And, how do I change that into an UIImage?

解决方案

Hello I had been reviewing your question and this are my results

I use your code and make some modifications this is my 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")
    }
}

as you can see here is a @IBOutlet weak var customImage: UIImageView! this is an outlet defined in my xib file for this custom cell, check this image

I hope this helps you, this works for me without problems

这篇关于尤里卡的自定义行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆