Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reload data after append new data or state? #20

Open
arimunandar opened this issue Mar 5, 2019 · 0 comments
Open

How to reload data after append new data or state? #20

arimunandar opened this issue Mar 5, 2019 · 0 comments

Comments

@arimunandar
Copy link

Hi @ishkawa ,

I need your help, i'm trying to insert new data or cell, but when i run collectionView.reloadData(), nothing happen,

final class AdvancedVenueDetailViewController: UIViewController {
    @IBOutlet private weak var collectionView: UICollectionView!
    
    private let dataSource = CollectionViewDataSource<AdvancedVenueDetailViewState.CellDeclaration> { cellDeclaration in
        switch cellDeclaration {
        case .outline(let venue):
            return VenueOutlineCell.makeBinder(value: venue)
        case .sectionHeader(let title):
            return SectionHeaderCell.makeBinder(value: title)
        case .review(let review):
            return ReviewCell.makeBinder(value: review)
        case .relatedVenue(let venue):
            return RelatedVenueCell.makeBinder(value: venue)
        }
    }
    
    private var state = AdvancedVenueDetailViewState()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
        layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
        collectionView.dataSource = dataSource
        dataSource.cellDeclarations = state.cellDeclarations
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            self.state.reviews.append(Review(authorImage: #imageLiteral(resourceName: "Kaminarimon_at_night"), authorName: "Yosuke Ishikawa", body: "Lorem ipsum."))
            self.collectionView.reloadData()
        }
    }
}

please help me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant