1
请求数据我已经设置了UICollectionView
与自定义数据源:UICollectionView不是从UICollectionViewDataSource
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
let dataSource = DataSource(storage)
let delegate = DelegateFlow()
layout.itemSize = CGSize(width: 90, height: 120)
paymentsHistory = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
paymentsHistory.delegate = delegate
paymentsHistory.dataSource = dataSource
paymentsHistory.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
self.view.addSubview(paymentsHistory)
Collection视图本身是正确显示,但没有出现细胞。
我可以从调试输出看到,
collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
和
collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
永远不会被调用。这是为什么?
你有没有尝试过在将其添加到'self.view'后尝试在集合视图中调用'reloadData()'? – D4ttatraya
它不会做任何事情@DashAndRest –
它不会调用,因为集合的高度为零,因此您需要检查collectionView的高度。 – KKRocks