Giter Club home page Giter Club logo

Comments (1)

mtnbarreto avatar mtnbarreto commented on May 12, 2024

We can change the cell of a particular row by setting up its cellProvider property.

Cell Type can not be changed since it's defined in the row type using generics.
Taking as an example the WeeklyDayRow, as we can see below it only works with WeekDayCell as its type defines.

public final class WeekDayRow: Row<Set<WeekDay>, WeekDayCell>, RowType

This is the CellProvider generic type:

public struct CellProvider<Cell: BaseCell where Cell: CellType> {

    /// Nibname of the cell that will be created.
    public private (set) var nibName: String?

    /// Bundle from which to get the nib file.
    public private (set) var bundle: NSBundle!


    public init(){}

    public init(nibName: String, bundle: NSBundle? = nil){
        self.nibName = nibName
        self.bundle = bundle ?? NSBundle(forClass: Cell.self)
    }

    /**
     Creates the cell with the specified style.

     - parameter cellStyle: The style with which the cell will be created.

     - returns: the cell
     */
    func createCell(cellStyle: UITableViewCellStyle) -> Cell {
        if let nibName = self.nibName {
            return bundle.loadNibNamed(nibName, owner: nil, options: nil).first as! Cell
        }
        return Cell.init(style: cellStyle, reuseIdentifier: nil)
    }
}

Since PushRow<T> cell must be a PushSelectorCell<T> and we can not use generic types from interface builder, the only option we have is go for custom rows.

In oder to use a xib file to load the view of your custom row cell, you should set up your custom row cellProvider property.

Code snippet bellow shows how WeekDayRow does it:

public final class WeekDayRow: Row<Set<WeekDay>, WeekDayCell>, RowType {

    required public init(tag: String?) {
        super.init(tag: tag)
        displayValueFor = nil
        cellProvider = CellProvider<WeekDayCell>(nibName: "WeekDaysCell")
    }
}

Regards

from eureka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.