DataSourceKit icon indicating copy to clipboard operation
DataSourceKit copied to clipboard

How to reload data after append new data or state?

Open arimunandar opened this issue 7 years ago • 0 comments

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

arimunandar avatar Mar 05 '19 04:03 arimunandar