FUITableViewCollectionSection
open class FUITableViewCollectionSection
The FUITableViewCollectionSection
control is designed to be used, when a section in a UITableView
should be dedicated to displaying a UICollectionView
, and, the height of that section should adjust to fit its contents.
The collection section produces a single FUICollectionViewTableViewCell
, which refreshes its height, after its subview FUICollectionView
calculates the sizes of its subview UICollectionViewCell
items.
A developer uses the FUITableViewCollectionSection
, by assigning a data source (/and delegate) to its collectionView: FUICollectionView
property; then, he or she should supply its collectionViewTableViewCell
property to a UITableViewDataSource.tableView(_:cellForRowAt:)
implementation.
Important
A developer should retain a strong reference to aFUITableViewCollectionSection
.
## Usage
let workorders: [WorkOrder] = [WorkOrder]()
override public func viewDidLoad() {
let workOrdersLayout = FUICollectionViewLayout.horizontalFlow
workOrdersLayout.itemSize = CGSize(width: 200, height: 200)
self.workOrdersSection = FUITableViewCollectionSection(tableView: self.tableView, collectionViewLayout: workOrdersLayout)
self.workOrdersSection.collectionView.dataSource = self
self.workOrdersSection.collectionView.register(FUISimpleCollectionViewCell.self, forCellWithReuseIdentifier: FUISimpleCollectionViewCell.reuseIdentifier)
self.workOrdersSection.collectionView.delegate = self
self.workOrdersSection.collectionView.isScrollEnabled = false
self.tableView.estimatedRowHeight = 98
#if swift(>=4.2)
self.tableView.rowHeight = UITableView.automaticDimension
#else
self.tableView.rowHeight = UITableViewAutomaticDimension
#endif
}
// MARK: UITableViewDataSource
override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return self.workOrdersSection.collectionViewTableViewCell
}
// MARK: UICollectionViewDataSource
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch collectionView {
case workOrdersSection.collectionView:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FUISimpleCollectionViewCell.reuseIdentifier,
for: indexPath) as! FUISimpleCollectionViewCell
cell.contentImageView.image = UIImage(named: "WorkOrderImage")
cell.titleLabel.text = "Work Order: \(indexPath.item)"
return cell
default:
// ...
}
}
-
Get the
UICollectionView
objectDeclaration
Swift
open var collectionView: UICollectionView { get }
-
Get the
FUICollectionViewTableViewCell
objectDeclaration
Swift
open var collectionViewTableViewCell: FUICollectionViewTableViewCell { get }
-
Get number of rows in the view
Declaration
Swift
open var rowCount: Int { get }