是完全静态的UICollectionView可能吗?

在UITableView中,完全静态的tableViewconfiguration是可能的。 您可以断开UITableView的数据源,并使用IB将每个单元格放在故事板(或xib)上。

我用UICollectionView尝试了同样的事情。 断开UICollectionView的数据源。 将每个单元放在故事板上的UICollectionView上。 我没有任何错误地build立它。 但它没有工作。 细胞根本不显示。

没有数据源的UICollectionView是可能的吗?

没有。

创build一个静态的UICollectionViewController是不允许的。 你必须有一个数据源委托。

我也想指出,没有一个静态的UITableView ,而是一个静态的UITableViewController 。 这是一个区别。

你可以很容易地创build一个静态的UICollectionViewController。

只需在界面构build器中创build每个单元格,给它们重用标识符(例如“Home_1”,“Home_2”,“Home_3”),然后填充方法如下:

 class HomeViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { let cellIdentifiers:[String] = ["Home_1","Home_2","Home_3"] let sizes:[CGSize] = [CGSize(width:320, height:260),CGSize(width:320, height:160),CGSize(width:320, height:100)] override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return cellIdentifiers.count } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { return collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifiers[indexPath.item], for: indexPath) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return sizes[indexPath.item] } } 

然后将视图控制器设置为适当的类,并且,嘿presto,(基本上)静态的集合。 我很抱歉地说,但这是BY FAR支持纵向和横向视图,当你有一组控件的最佳方式…