Reputation: 331
I am trying out IGListKit for the first time but i seem to have hit a brick wall early on
lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
collectionView.backgroundColor = .white
return collectionView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.collectionView)
let updater = ListAdapterUpdater()
let adapter = ListAdapter(updater: updater, viewController: self, workingRangeSize: 0)
adapter.collectionView = self.collectionView
adapter.dataSource = self
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.frame = view.bounds
}
And
extension SocialViewController: ListAdapterDataSource {
func objects(for listAdapter: ListAdapter) -> [ListDiffable] {
// this can be anything!
return [ "Foo" as ListDiffable, "Bar" as ListDiffable]
}
func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
return TopNewsSectionController()
}
func emptyView(for listAdapter: ListAdapter) -> UIView? {
return UIImageView(image: UIImage(named: "swords"))
}
}
class TopNewsSectionController: ListSectionController {
override func sizeForItem(at index: Int) -> CGSize {
return CGSize(width: collectionContext!.containerSize.width, height: 55)
}
override func cellForItem(at index: Int) -> UICollectionViewCell {
return collectionContext!.dequeueReusableCell(of: TopNewsCollectionViewCell.self, for: self, at: index)
}
}
but my neither cellForItem or sizeForItem is being called what am i doing wrong?
Upvotes: 1
Views: 1124
Reputation: 1
Your adapter
object is destroyed when viewDidLoad
returns. Try to declare it as a property of your ViewController
.
Upvotes: 0
Reputation: 138
Try to declare adapter as a class property rather than a method property,
let updater = ListAdapterUpdater()
let adapter = ListAdapter(updater: updater, viewController: self, workingRangeSize: 0)
adapter.collectionView = self.collectionView
to
lazy var adapter: ListAdapter = {
return ListAdapter(updater: ListAdapterUpdater(), viewController: self, workingRangeSize: 0)
}()
Upvotes: 1
Reputation: 1
Call adapter.performUpdatesAnimated
or adapter.reloadDataWithCompletion
(for the first time loading) to update
Upvotes: 0