Kolaylıkla bir statik UICollectionViewController oluşturabilirsiniz.
sadece arayüz oluşturucu her hücreyi oluşturmak vermek bunları yeniden kullanım tanımlayıcılar (örneğin, "Home_1" "Home_2" "Home_3"), aşağıdaki gibi yöntemler doldurmak:
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]
}
}
sonra görünüm denetleyicisi ayarlamak uygun sınıftan ve (temelde) statik bir koleksiyona sahip olmak. Söylemek üzüldüm ama bu kontrol gruplarına sahip olduğunuzda, portre ve manzara görünümlerini desteklemenin en iyi yoludur ...
Hücrelerinizi "cellForItemAtIndexPath" içine oluşturduğunuzda, sabit bir hücre dizisine erişebilirsiniz. dequeueReusableCellWithReuseIdentifier' kullanmadan. Sadece bunun için gerçekten güçlü bir kullanım durumunuz varsa, hatalara ve performans sorunlarına yol açma olasılığı daha yüksektir. –