The StorytellerGridView
inherits from StorytellerListView
(see StorytellerListView)
All of the properties and methods from StorytellerListView apply to the StorytellerGridView.
func reloadData(cell: UITableViewCell, tableView: UITableView)
When using StorytellerGridView
inside UITableViewCell
then number of stories influences the height of the grid hence overall height of the UITableViewCell
. During reusing cell it is required to pass cell and tableView to adjust it height outside from StorytellerGridView
.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(
withIdentifier: StorytellerTableViewCell.defaultCellReuseIdentifier,
for: indexPath) as? StorytellerTableViewCell
else {
fatalError("Proper cell was not found in UITableView")
}
cell.reloadData(cell: cell, tableView: tableView)
return cell
}
A StorytellerGridViewDelegate
has methods for managing StorytellerGridView
events.
You can implement these optional methods when responding to the StorytellerGridViewDelegate
protocol:
contentSizeDidChange
- this method is called when the size of the grid changes. This can occur after calling reloadData
when new stories are fetched from the server or when a user's device is rotated.class StorytellerGridViewDelegateImplementation : StorytellerGridViewDelegate {
func contentSizeDidChange(_ size: CGSize) {
// calculated size of grid
}
}
Once an instance of this has been created, you can then set it to the gridDelegate
property of your StorytellerGridView
as follows:
let storytellerGrid = StorytellerGridView()
let delegate = StorytellerGridViewDelegateImplementation()
storytellerGrid.gridDelegate = delegate
storytellerGrid.reloadData()
Attributes can be applied to any StorytellerGridView
instance in code or under the Attributes Inspector in the Storyboard.