यह वह जगह है संभव है, आपको बस प्रत्येक UICollectionView को सबव्यूव के रूप में जोड़ने की आवश्यकता है, और प्रतिनिधि और डेटा स्रोत को अपने UIViewController पर सेट करें।
यहां एक त्वरित उदाहरण है।
let collectionViewA = UICollectionView()
let collectionViewB = UICollectionView()
let collectionViewAIdentifier = "CollectionViewACell"
let collectionViewBIdentifier = "CollectionViewBCell"
override func viewDidLoad() {
// Initialize the collection views, set the desired frames
collectionViewA.delegate = self
collectionViewB.delegate = self
collectionViewA.dataSource = self
collectionViewB.dataSource = self
self.view.addSubview(collectionViewA)
self.view.addSubview(collectionViewB)
}
cellForItemAtIndexPath प्रतिनिधि समारोह में:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if collectionView == self.collectionViewA {
let cellA = collectionView.dequeueReusableCellWithReuseIdentifier(collectionViewAIdentifier) as UICollectionViewCell
// Set up cell
return cellA
}
else {
let cellB = collectionView.dequeueReusableCellWithReuseIdentifier(collectionViewBIdentifier) as UICollectionViewCell
// ...Set up cell
return cellB
}
}
numberOfItemsInSection समारोह में मान लें कि आप एक UICollectionView काम कर रहे है, तो आप काफी आसानी से एक दूसरे को जोड़ने के लिए अपने स्वयं के उपयोग के लिए इस कोड को अनुकूलित करने के लिए सक्षम होना चाहिए :
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.collectionViewA {
return 0 // Replace with count of your data for collectionViewA
}
return 0 // Replace with count of your data for collectionViewB
}
मुझे यह त्रुटि मिलती है "UICollectionView को इस लाइन पर एक गैर-शून्य लेआउट पैरामीटर के साथ प्रारंभ किया जाना चाहिए" संग्रह ViewA = UICollectionView() " – dennis
यह मेरे लिए काम नहीं किया गया है! मुझे यह त्रुटि मिली: *** अपरिपक्व अपवाद के कारण ऐप को समाप्त करना 'एनएसआईएनवालिडअर्गमेंट एक्सेप्शन', कारण: 'यूआईसीओलेक्शन व्यू को गैर-शून्य लेआउट पैरामीटर के साथ आरंभ किया जाना चाहिए' –