2016-07-04 60 views
1

我正在嘗試創建一個顯示圖像的自定義行。於是我開始試圖在尤里卡的網頁表示的基本自定義行: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的?

+0

你有CustomCell2筆尖定義? –

+0

我想我沒有那個。我不知道該怎麼做。 –

+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!這是一個在此定製的電池我的廈門國際銀行文件中定義的插座,檢查這一形象

enter image description here

我希望這可以幫助你,這對我工作沒有問題