RSDTableStepViewController

open class RSDTableStepViewController: RSDStepViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, RSDFormStepDataSourceDelegate, RSDPickerObserver

RSDTableStepViewController is a custom instance of RSDStepViewController. Its subviews include a UITableView, a RSDNavigationFooterView, which may or may not be embedded in the tableView as its footerView, and a RSDNavigationHeaderView, which is embedded in the tableView as its headerView.

This class populates the contents and properties of the headerView and navigationView based on the associated RSDStep, which is expected to be set before presenting the view controller.

An instance of RSDFormStepDataSource is created by setupModel() and assigned to property tableData. This method is called by viewWillAppear() and serves as the UITableViewDataSource. The tableData also keeps track of answers that are derived from the user’s input and it provides the RSDResult that is appended to the RSDTaskPath associated with this task.

This class is responsible for acquiring input from the user, validating it, and supplying it as an answer to to the model (tableData). This is typically done in delegate callbacks from various input views, such as UITableView (didSelectRow) or UITextField (valueDidChange or shouldChangeCharactersInRange).

Some RSDSteps, such as RSDFactory.StepType.instruction, require no user input (and have no input fields). These steps will result in a tableData that has no sections and, therefore, no rows. So the tableView will simply have a headerView, no rows, and a footerView.

  • The table view associated with this view controller. This will be created during viewDidLoad() with a default set up if it is nil. If this view controller is loaded from a nib or storyboard, then it should set this outlet using the interface builder.

    Declaration

    Swift

    @IBOutlet open var tableView: UITableView!
  • The data source for this table.

    Declaration

    Swift

    open var tableData: RSDFormStepDataSource?
  • Convenience property for accessing the form step (if casting the step to a RSDFormUIStep is applicable).

    Declaration

    Swift

    public var formStep: RSDFormUIStep?
  • Class method to determine if this view controller class supports the provided step’s form input fields. This will vary based on the RSDFormDataType and `RSDFormUIHint’ for each of the input fields in the step.

    Declaration

    Swift

    open class func doesSupportInputFields(in inputFields: [RSDInputField]) -> Bool
  • Static method to determine if this view controller class supports the provided step.

    Declaration

    Swift

    open class func doesSupport(_ step: RSDStep) -> Bool
  • Should the view controller tableview include a header? If true, then by default, a RSDStepHeaderView will be added in viewDidLoad() if the view controller was not loaded using a storyboard or nib that included setting the navigationFooter property.

    Declaration

    Swift

    open var shouldShowHeader: Bool = true
  • Should the view controller tableview include a footer? If true, then by default, a RSDNavigationFooterView will be added in viewDidLoad() if the view controller was not loaded using a storyboard or nib that included setting the navigationFooter property.

    Declaration

    Swift

    open var shouldShowFooter: Bool = true
  • Override viewDidLoad() to add the table view, navigation header, and navigation footer if needed.

    Declaration

    Swift

    override open func viewDidLoad()
  • Override viewWillAppear() to set up the tableData data source model and add a keyboard listener.

    Declaration

    Swift

    override open func viewWillAppear(_ animated: Bool)
  • Override viewDidAppear() to focus on the first text field if applicable.

    Declaration

    Swift

    override open func viewDidAppear(_ animated: Bool)
  • Override viewWillDisappear() to remove listeners and dismiss the keyboard.

    Declaration

    Swift

    override open func viewWillDisappear(_ animated: Bool)
  • Override viewDidLayoutSubviews() to set up the navigation footer either as the table footer or as a sticky footer.

    Declaration

    Swift

    override open func viewDidLayoutSubviews()
  • The UI hints that are supported by this view controller.

    Declaration

    Swift

    open class var supportedUIHints: Set<RSDFormUIHint>
  • Creates and assigns a new instance of the model. The default implementation will instantiate RSDFormStepDataSourceObject and set this as the tableData.

    Declaration

    Swift

    open func setupModel()
  • Register the given reuse identifier. This is a factory method that is called before dequeuing a table cell. Overrides of this method should first check to see if the reuse identifier has already been registered and if not, do so by calling tableView.register(, forCellReuseIdentifier:) with either a nib or a class.

    Declaration

    Swift

    open func registerReuseIdentifierIfNeeded(_ reuseIdentifier: String)
  • Override the set up of the header to set the background color for the table view and adjust the minimum height.

    Declaration

    Swift

    open override func setupHeader(_ header: RSDNavigationHeaderView)
  • Auto layout constraint constants for the margin used at the bottom of the main view and the default tableView row height.

    Declaration

    Swift

    open var constants: RSDTableStepLayoutConstants

    Return Value

    A struct with the layout constants

  • Specifies whether the next button should be enabled based on the validity of the answers for all form items.

    Declaration

    Swift

    override open var isForwardEnabled: Bool
  • Declaration

    Swift

    override open func goForward()
  • Declaration

    Swift

    override open func stop()
  • Return the number of sections. The default implementation returns the section count of the tableData data source.

    Declaration

    Swift

    open func numberOfSections(in tableView: UITableView) -> Int

    Parameters

    tableView

    The table view.

    Return Value

    The number of sections.

  • Return the number of rows in a given section. The default implementation returns the row count of the tableData data source.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int

    Parameters

    tableView

    The table view.

    section

    The section for the table view.

    Return Value

    The number of rows in the given section.

  • Instantiate or dequeue a cell for the given index path. The default implementation will call dequeueCell(in:, at:) to dequeue the cell followed by calling configure(cell:, in:, at:) to configure the cell.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

    Parameters

    tableView

    The table view.

    indexPath

    The given index path.

    Return Value

    The table view cell configured for this index path.

  • Dequeue a cell that is appropriate for the item at the given index path. By default, this method will call reuseIdentifier(for:) followed by registerReuseIdentifierIfNeeded() to register the table view cell reuse identifier before calling dequeueReusableCell() on the given table view.

    Declaration

    Swift

    open func dequeueCell(in tableView: UITableView, for indexPath: IndexPath) -> UITableViewCell

    Parameters

    tableView

    The table view.

    indexPath

    The given index path.

    Return Value

    The table view cell dequeued for this index path.

  • Returns the cell reuse identifier for a given index path.

    By default, this will look for a RSDTableItem at the given index path and return the reuseIdentifier property on that object. If there isn’t a table item in the tableData associated with this index path then this is a failure. The default behavior is to throw an assertion and return a placeholder cell identifier.

    Declaration

    Swift

    open func reuseIdentifier(for indexPath: IndexPath) -> String

    Parameters

    indexPath

    The given index path.

    Return Value

    The reuse identifier for the given index path.

  • Configure a cell that is appropriate for the item at the given index path.

    Declaration

    Swift

    open func configure(cell: UITableViewCell, in tableView: UITableView, at indexPath: IndexPath)

    Parameters

    cell

    The cell to configure.

    tableView

    The table view.

    indexPath

    The given index path.

  • Instantiate the appropriate picker view for the given input item.

    Declaration

    Swift

    open func instantiatePickerView(textInputItem: RSDTextInputTableItem, indexPath:IndexPath) -> (RSDPickerViewProtocol & UIView)?

    Parameters

    textInputItem

    The table item.

    indexPath

    The index path.

  • Handle the selection of a row.

    The base class implementation can handle the following ui hints:

    1. List - Selects the given index path as the current selection. This will also deselect other rows if the form data type is single choice.
    2. Textfield - Calls becomeFirstResponder() to present the keyboard.

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
  • When a text field gets focus, assign it as the active text field (to allow resigning active if the user taps the forward button) and scroll it into view above the keyboard.

    Declaration

    Swift

    open func textFieldDidBeginEditing(_ textField: UITextField)
  • Resign first responder on Enter key tapped.

    Declaration

    Swift

    open func textFieldShouldReturn(_ textField: UITextField) -> Bool
  • Enable the next button as soon as the text field entry has changed.

    Declaration

    Swift

    open func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
  • Validate and save the text field result.

    Declaration

    Swift

    open func textFieldDidEndEditing(_ textField: UITextField)
  • Undocumented

    Declaration

    Swift

    @objc open func pickerValueChanged(_ sender: Any)
  • Get the index path associated with a given text field.

    Declaration

    Swift

    public func indexPath(for textField: UITextField?) -> IndexPath?
  • Get the table item associated with a given text field.

    Declaration

    Swift

    public func tableItem(for textField: UITextField?) -> RSDTextInputTableItem?
  • Validate the text field value and save the answer if valid.

    Declaration

    Swift

    public func validateAndSave(textField: UITextField) -> Bool
  • Save answer back to the data source.

    Declaration

    Swift

    open func saveAnswer(newValue: Any, at indexPath: IndexPath) -> Bool
  • Show a validation error message that is appropriate for the given context.

    Declaration

    Swift

    open func showValidationError(title: String?, message: String?, context: RSDInputFieldError.Context?, at indexPath: IndexPath)
  • Called when the answers tracked by the data source change.

    Declaration

    Swift

    open func answersDidChange(in section: Int)

    Parameters

    section

    The section that changed.