jeudi 2 mars 2017

Swift: delegation patterns in terms of reloading data?

I have a UICollectionView within a UICollectionView. One is a row with collection view cells that can scroll horizontally (think of Apple's iOS App Store). Let's call the row collection view Category and its one cell row, called PostCells, then registers more cells (to get the horizontal items).

Now here's the problem.

I want to pull down to refresh, but Category is not in charge of the data source for the horizontal cells. I can pull down to refresh but how can Category tell PostCells that it just refreshed?

Here's a rough example of what I mean:

class Category: UICollectionViewController {
    // registers the cell for a row.
    // target for pull to refresh is here
    // collection view methods.


class PostCells: UICollectionViewCell {
    // collection view object, which then registers items to scroll horizontally.
    // downloads data from a remote api, assigns Post values.

class Posts: UICollectionViewCell {
    // name, photo, username, message
}

What's the recommended design pattern to stop the spinner (inside Category once the data returns a response, and to actually reload the collection views? I feel like the two classes need to have delegates set to each other.

Aucun commentaire:

Enregistrer un commentaire