Skip to content

Built in Schemes

James Richard edited this page Dec 19, 2015 · 7 revisions

These are the Scheme classes that are currently provided by TableSchemer. Note that in each section, handling height and selection are dependent on the delegate forwarding these tasks to the TableScheme instance.

BasicScheme

This is your most basic scheme type. It represents a single cell, and is probably the most common Scheme you'll use. It takes a single Generic type that represents to cell type.

A BasicScheme requires a reuseIdentifier and a configurationHandler. The reuseIdentifier is used to dequeue a cell, and the configurationHandler is called when the cell is configured.

A BasicScheme also supports height, which defaults to using the table height, and a selection handler for when the user selects a cell.

Example:

builder.buildScheme { (scheme: BasicSchemeBuilder) in
    scheme.height = .Custom(80.0)
    scheme.configurationHandler = { cell in
        cell.textLabel.text = "Tap here to see the next controller"
        cell.accessoryType = .DisclosureIndicator
    }
                    
    scheme.selectionHandler = { [unowned self] cell, scheme in
        let controller = SomeViewController()
        self.navigationController.pushViewController(controller, animated: true)
    }
}

AccordionScheme

This scheme allows you to have a single cell that expands into multiple cells to allow an interface similar to dropdown selection. It inherits from BasicScheme, and requires two Generic types. The first is the type of cell used for the accordion when it isn't expanded, and the second is the type of the cells used when the accordion is expanded. Accordions are allowed to have a different cell type for each expanded cell, and if you're taking advantage of that feature you'll have to make this type the root cell type of all the accordion cells.

An AccordionScheme requires expandedCellTypes (an array of cell type for each expanded cell. This array also represents how many expanded cells there are), and an accordionConfigurationHandler to configure the expanded cells. These are required in addition to the BasicScheme requirements since AccordionScheme subclasses it.

An AccordionScheme also supports accordionHeights (An array of RowHeight objects representing the height of each expanded cell), and an accordionSelectionHandler (Called when an expanded accordion cell is selected)

Important: The TableScheme must be asked to handle selection for the interactive functionality of AccordionScheme to work.

Example:

builder.buildSchemeSet { builder in
    builder.headerText = "Accordion Sample"
    
    builder.buildScheme { (scheme: AccordionSchemeBuilder) in
        scheme.expandedCellTypes = [UITableViewCell.Type](count: 3, repeatedValue: UITableViewCell.self)
        scheme.height = .Custom(44.0)
        scheme.accordionHeights = [.UseTable, .Custom(88.0)]
        scheme.configurationHandler = { cell in 
            // Configure the cell
        }
        
        scheme.selectionHandler = { cell, scheme in
            // Called when the collapsed cell is tapped
        }
        
        scheme.accordionConfigurationHandler = { cell, index in
            // Called when an expanded cell is being configured
        }
        
        scheme.accordionSelectionHandler = {  cell, scheme, selectedIndex in
            // Called when an expanded cell is tapped
        }
    }
}

ArrayScheme

This scheme allows you to embed an array of cells in your table with one scheme. It takes two Generics. The first is the type of object stored in the array, and the second is the type of cell that will be shown to the user.

An ArrayScheme requires objects (An array of the objects that will be used), and a configurationHandler which will be called when the cell is configured.

An ArrayScheme also supports a heightHandler (A closure called when height for the cell is requested; passes in the object), and a selectionHandler for when a row is selected.

Example:

builder.buildScheme { (scheme: ArraySchemeBuilder<String, UITableViewCell>) in
    scheme.objects = ["Foo", "Bar"]
    
    scheme.heightHandler = { object in
        return .Custom(44.0)
    }
    
    scheme.configurationHandler = { cell, object in
        // Configure the cell
    }
    
    scheme.selectionHandler = { cell, scheme, object in
        // Handle selection of a cell
    }
}

RadioScheme

This scheme allows you to present a group of cells that act similar to a radio group. One cell is allowed to be selected at a time, and the selected cell will set the accessoryType to .Checkmark.

A RadioScheme requires an array of cell types (which will also dictate how many cells the RadioScheme has), and a configurationHandler which will be called for each cell in the RadioScheme.

A RadioScheme also supports an array of heights, and a selectionHandler for when a row is selected.

Important: The TableScheme must be asked to handle selection for the interactive functionality of RadioScheme to work.

Example:

builder.buildScheme { (scheme: RadioSchemeBuilder) in
    scheme.expandedCellTypes = [UITableViewCell.Type](count: 5, repeatedValue: UITableViewCell.self)
    
    scheme.configurationHandler = { cell, index in
        // Configure the cell
    }
    
    scheme.selectionHandler = { cell, scheme, index in
        // Handle selection of the cell
    }
}

Custom Schemes

Be sure to check out how to create custom schemes if none of the built-in schemes seem appropriate!