2016-07-04 2 views
1

J'essaie de créer une ligne personnalisée qui affiche une image. Alors j'ai commencé en essayant la ligne de base sur mesure indiquée dans la page de Eureka: https://github.com/xmartlabs/Eureka#basic-custom-rowsLigne personnalisée dans Eureka

Voici le code que je utilise:

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

Et qui est enregistré comme CustomCell2.swift. J'appelle cette ligne personnalisée en utilisant ceci: futurSection <<< CustomRow ("")

Mais je reçois une erreur: Could not load NIB in bundle with name 'CustomCell2'

Et, comment puis-je changer cela dans un UIImage?

+0

Vous avez défini la plume de CustomCell2? –

+0

Je suppose que je n'ai pas ça. Je n'ai aucune idée de comment le faire. –

+0

ok, je vais vérifier et afficher un résultat, salutations –

Répondre

4

Bonjour j'avais été l'examen de votre question et ce sont mes résultats

J'utilise votre code et apporter quelques modifications ceci est mon 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") 
    } 
} 

que vous pouvez voir ici est un @IBOutlet weak var customImage: UIImageView! c'est un sortie définie dans mon fichier pour cette cellule xib personnalisé, vérifiez cette image

enter image description here

J'espère que cela vous aide, cela fonctionne pour moi sans problèmes