RSDTableDataSource
public protocol RSDTableDataSource : RSDStepViewPathComponent
RSDTableDataSource
is the model for a table view controller. It provides the UITableViewDataSource,
manages and stores answers provided through user input, and provides an RSDResult
with those answers upon
request.
It also provides several convenience methods for saving or selecting answers, checking if all answers are valid, and retrieving specific model objects that may be needed by the view controller.
The tableView data source is comprised of 2 objects:
RSDTableSection
: An object representing a section in the tableView. It has one or moreRSDTableItem
objects.RSDTableItem
: An object representing a specific table cell. There will be oneRSDTableItem
for each indexPath in the tableView.RSDTableItemGroup
: An object representing a specific question supplied byRSDStep
as an input field. Upon init(), the ItemGroup will create one or moreRSDTableItem
objects representing the answer options for theRSDInputField
. The ItemGroup is responsible for storing/computing the answers for itsRSDInputField
.
-
The delegate associated with this data source.
Declaration
Swift
var delegate: RSDTableDataSourceDelegate? { get set }
-
The table sections for this data source.
Declaration
Swift
var sections: [RSDTableSection] { get }
-
Retrieve the ‘RSDTableItemGroup’ for a specific IndexPath.
Declaration
Swift
func itemGroup(at indexPath: IndexPath) -> RSDTableItemGroup?
Parameters
indexPath
The index path that represents the item group in the table view.
Return Value
The requested
RSDTableItemGroup
, or nil if it cannot be found. -
Determine if all answers are valid. Also checks the case where answers are required but one has not been provided.
Declaration
Swift
func allAnswersValid() -> Bool
Return Value
A
Bool
indicating if all answers are valid. -
Save an answer for a specific IndexPath.
Throws
RSDInputFieldError
if the answer is invalid.Declaration
Swift
func saveAnswer(_ answer: Any, at indexPath: IndexPath) throws
Parameters
answer
The object to be save as the answer.
indexPath
The
IndexPath
that represents theRSDTableItem
in the table view. -
Select or deselect the answer option for a specific IndexPath.
Throws
RSDInputFieldError
if the selection is invalid.Declaration
Swift
func selectAnswer(item: RSDTableItem, at indexPath: IndexPath) throws -> (isSelected: Bool, reloadSection: Bool)
Parameters
item
The table item that was selected or deselected.
indexPath
The
IndexPath
that represents theRSDTableItem
in the table view.Return Value
- isSelected: The new selection state of the selected item.
- reloadSection:
true
if the section needs to be reloaded b/c other answers have changed, otherwise returnsfalse
.
-
tableItem(at:)
Extension methodRetrieve the
RSDTableItem
for a specificIndexPath
.Declaration
Swift
public func tableItem(at indexPath: IndexPath) -> RSDTableItem?
Parameters
indexPath
The
IndexPath
that represents the table item in the table view.Return Value
The requested
RSDTableItem
, or nil if it cannot be found. -
nextItem(after:)
Extension methodRetrieve the next table item after the current one at the given index path.
Declaration
Swift
public func nextItem(after indexPath: IndexPath) -> RSDTableItem?
Parameters
indexPath
The index path that represents the item group in the table view.
Return Value
The next
RSDTableItem
ornil
if this was the last item.