2017-05-31 57 views
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 

永远不会被调用。这是为什么?

+0

你有没有尝试过在将其添加到'self.view'后尝试在集合视图中调用'reloadData()'? – D4ttatraya

+0

它不会做任何事情@DashAndRest –

+0

它不会调用,因为集合的高度为零,因此您需要检查collectionView的高度。 – KKRocks

回答

1

我的猜测是它被取消引用,因为UICollectionView中的delegatedatasource是弱引用。

weak open var delegate: UICollectionViewDelegate? 
weak open var dataSource: UICollectionViewDataSource? 

一旦你超出了你所在的任何函数的范围,它应该被设为零。

它应该工作,如果你使它成为你的班级的财产。

相关问题