我是第一次尝试 IGListKit,但我似乎很早就遇到了障碍
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
}
和
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"))
}
}
类 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)
}
}
但是我的 cellForItem 或 sizeForItem 都没有被称为我做错了什么?