आप आसानी से एक स्थिर UICollectionViewController बना सकते हैं। उन्हें
बस इंटरफ़ेस बिल्डर की हर कोशिका बनाने के लिए, देना फिर से उपयोग पहचानकर्ता (उदाहरण के लिए "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]
}
}
तब दृश्य नियंत्रक सेट उचित वर्ग के होने के लिए, और, हे प्रतिष्ठा, एक (मूल रूप से) स्थैतिक संग्रह। मैं कहना है माफी चाहता हूँ, लेकिन इस सुदूर पोर्ट्रेट और लैंडस्केप विचारों का समर्थन करने के लिए आप नियंत्रण के समूह है जब सबसे अच्छा तरीका है ...
स्रोत
2016-09-14 21:31:11
जब आप 'cellForItemAtIndexPath' आप बल्कि कोशिकाओं की एक स्थिर सरणी का उपयोग कर सकता है में अपनी कोशिकाओं का निर्माण 'dequeueReusableCellWithReuseIdentifier' का उपयोग करने से। मैं केवल तभी ऐसा करूंगा यदि आपके पास इसके लिए वास्तव में मजबूत उपयोग केस है, क्योंकि यह बग और प्रदर्शन समस्याओं का कारण बनने की अधिक संभावना है। –