StorytellerGridView

The StorytellerGridView inherits from StorytellerListView (see StorytellerListView)

Attributes

  • startInset - the top-inset of the Stories inside the row, default value is 0
  • endInset - the bottom-inset of the Stories inside the row, default value is 0
  • cellSpacing - the spacing of Stories inside the grid is handled horizontally and vertically, default value is 4

StorytellerGridView specific attributes:

  • numberOfColumns - the number of columns used in the grid, default value is 2
  • gridDelegate - the StorytellerGridViewDelegate instance for StorytellerGridView callbacks

Methods

reloadData

func reloadData(cell: UITableViewCell, tableView: UITableView)

When using StorytellerGridView inside UITableViewCell then the 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
}

GridDelegate

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()

Storyboard

Attributes can be applied to any StorytellerGridView instance in code or under the Attributes Inspector in the Storyboard.

PREVIOUS
Forward Arrow