BaseCollectionController
open class BaseCollectionController<T> : NSObject, CollectionController
An abstract base class for providing data and handling actions for a CollectionViewController
.
This is a generic NSObject conforming to UICollectionViewDataSource
, UICollectionViewDelegate
, UISearchBarDelegate
and ContentLoader
protocols.
This class is to be subclassed to comply to a specific behavior.
The associated type of this class will be used to initialize it’s CollectionDataProvider
property. By default, the init(collecitonView:)
initialization method assigns the collection view property and sets it up using the setupCollectionView
method.
This class also supports data filtering through UISearchBarDelegate
searchBar(_:,textDidChange:)
method. It calls the updateFilteredData
to update the filtered CollectionDataProvider
property. The filteredData(with:)
is called to filter the data using the search string.
Note
Due to what maybe seems to be a bug with the Swift, methods not initially in the superclass and implemented in the subclass may not be executed. To get around this, the method needs to have an@objc
attribue.
-
Declaration
Swift
open weak var statefulViewController: StatefulViewController?
-
The
statefulViewController
cast as aCollectionViewController
.Declaration
Swift
open var collectionViewController: CollectionViewController? { get }
-
The data provider of the
CollectionController
.Declaration
Swift
open var provider: CollectionDataProvider<T>
-
An optional filtered data provider of the
CollectionController
.Declaration
Swift
open lazy var filteredProvider: CollectionDataProvider<T> { get set }
-
Determines whether the data is supposed to be filtered or not.
Declaration
Swift
open var isFiltered: Bool
-
The collection view to provide data and handle actions for.
Declaration
Swift
open weak var collectionView: UICollectionView? { get set }
-
The layout for the collection view.
Declaration
Swift
open var collectionViewLayout: UICollectionViewLayout { get }
-
Represents whether the collection controller is fetching content.
Declaration
Swift
open var isFetching: Bool
-
Undocumented
Declaration
Swift
override public init()
-
Returns a newly initialized collection controller with the specified collection view to provide data and handle actions for.
Declaration
Swift
public init(collectionView: UICollectionView? = nil)
Parameters
collectionView
The collection view to associate with.
Return Value
The initialized collection controller.
-
Sets up the collection view’s layout, dataSource, delegate properties, and registers components to the collection view.
Declaration
Swift
open func setupCollectionView()
-
Register components to the collection view.
Declaration
Swift
open func registerComponents()
-
Returns the item at the specified index path from either the
provider
or thefilteredProvider
depending on the value ofisFiltered
.Declaration
Swift
open func dataItem(at indexPath: IndexPath) -> T?
Parameters
indexPath
The index path for the item.
Return Value
Returns the item data.
-
Updates the filtered data given the search term.
If the search term is empty, this sets
isFiltered
to false. Otherwise, this removes all data from the filtered data provider and gets new filtered data fromfilterData(with:)
then setsisFiltered
to true. The collection view is then reloaded afterwards.Declaration
Swift
open func updateFilteredData(with searchTerm: String)
Parameters
searchTerm
The search term to use as filter.
-
Returns the filtered data from the data provider.
Declaration
Swift
open func filteredData(with searchTerm: String) -> [T]
Parameters
searchTerm
The search term to use as filter.
Return Value
Returns the filtered data.
-
Undocumented
Declaration
Swift
open func numberOfSections(in collectionView: UICollectionView) -> Int
-
Undocumented
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
-
Undocumented
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
-
Undocumented
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
-
Undocumented
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
-
Declaration
Swift
open func loadContent()
-
Declaration
Swift
open func refreshContent()
-
Undocumented
Declaration
Swift
open func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool
-
Undocumented
Declaration
Swift
open func searchBarTextDidBeginEditing(_ searchBar: UISearchBar)
-
Undocumented
Declaration
Swift
open func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool
-
Undocumented
Declaration
Swift
open func searchBarTextDidEndEditing(_ searchBar: UISearchBar)
-
Undocumented
Declaration
Swift
open func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
-
Undocumented
Declaration
Swift
open func searchBar(_ searchBar: UISearchBar, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
-
Undocumented
Declaration
Swift
open func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
-
Undocumented
Declaration
Swift
open func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar)
-
Undocumented
Declaration
Swift
open func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
-
Undocumented
Declaration
Swift
open func searchBarResultsListButtonClicked(_ searchBar: UISearchBar)
-
Undocumented
Declaration
Swift
open func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int)