Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PushRow on CustomRow xib #64

Closed
sagits opened this issue Oct 29, 2015 · 1 comment
Closed

Use PushRow on CustomRow xib #64

sagits opened this issue Oct 29, 2015 · 1 comment

Comments

@sagits
Copy link

sagits commented Oct 29, 2015

Hi, i'm trying to create a customRow with 2 fields and a pushRow inside it. Is this possible? How can i import pushrow inside my customCell.xib, its extended from UiView? Thanks in advance.

@mtnbarreto
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants