मुझे संग्रह दृश्य कक्ष के हिस्से के रूप में संग्रहदृश्य होने में रूचि है, लेकिन किसी कारण से यह पता नहीं लगाया जा सकता कि यह कैसे किया जाएगा। सेल संग्रह संग्रह के लिए आवश्यक विधियों को मैं कहां लागू करूं?UICollectionView में UICollectionViewCell
उत्तर
an article that Ash Furrow wrote है जो के अंदर UICollectionView
डालने का तरीका बताता है। UICollectionViewCell
के अंदर इसका उपयोग करते समय यह मूल रूप से वही विचार है।
यह उत्तर के लिए बहुत देर हो चुकी है लेकिन यह दूसरों की मदद कर सकती है। यह का UICollectionViewCell
के अंदर एक उदाहरण है।
mainCollectionView
होने से शुरू करते हैं। तो फिर इस संग्रह की प्रत्येक कोशिका पर बना सकते हैं और ऐसा करने के लिए एक नया UICollectionView
और सही जगह प्रारंभ कि UICollectionView
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath)
मैं MainCollectionViewCell
यहाँ प्रारंभ करें और फिर MainCollectionViewCell
एक बनाने के लिए तर्क संभालती है जैसे नई UICollectionView
guard let collectionViewCell = cell as? MainCollectionViewCell else { return }
collectionViewCell.delegate = self
let dataProvider = ChildCollectionViewDataSource()
dataProvider.data = data[indexPath.row] as NSArray
let delegate = ChildCollectionViewDelegate()
collectionViewCell.initializeCollectionViewWithDataSource(dataProvider, delegate: delegate, forRow: indexPath.row)
collectionViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? 0
यहाँ MainCollectionViewCell
पर प्रारंभकर्ता है कि एक नए UICollectionView
func initializeCollectionViewWithDataSource<D: protocol<UICollectionViewDataSource>,E: protocol<UICollectionViewDelegate>>(dataSource: D, delegate :E, forRow row: Int) {
self.collectionViewDataSource = dataSource
self.collectionViewDelegate = delegate
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .Horizontal
let collectionView = UICollectionView(frame: self.bounds, collectionViewLayout: flowLayout)
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseChildCollectionViewCellIdentifier)
collectionView.backgroundColor = UIColor.whiteColor()
collectionView.dataSource = self.collectionViewDataSource
collectionView.delegate = self.collectionViewDelegate
collectionView.tag = row
self.addSubview(collectionView)
self.collectionView = collectionView
collectionView.reloadData()
}
उम्मीद है कि मदद करता है !!
मैंने इसके लिए एक उदाहरण दिया और जिथब पर डाल दिया। यह UICollectionViewCell
के अंदर उपयोग का प्रदर्शन करता है।
https://github.com/irfanlone/Collection-View-in-a-collection-view-cell
सब कुछ प्रोग्राम के किया जाता है। कोई स्टोरीबोर्ड नहीं
मैंने अपने UICollectionViewCell के अंदर एक UICollectionView जोड़ा। मैं भी बनाया UICollectionView अंदर फिर से एक UICollectionViewCell जोड़ने के बारे में इस परिणाम
import UIKit
class CategoryCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
private let cellId = "cell"
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let appsCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
return collectionView
}()
func setupViews() {
backgroundColor = .blue
addSubview(appsCollectionView)
appsCollectionView.delegate = self
appsCollectionView.dataSource = self
appsCollectionView.register(AppCell.self, forCellWithReuseIdentifier: cellId)
addConstrainstWithFormat("H:|-8-[v0]-8-|", views: appsCollectionView)
addConstrainstWithFormat("V:|[v0]|", views: appsCollectionView)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
return cell
}
}
class AppCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupViews(){
backgroundColor = .red
}
}
मेरे UICollectionViewController
import UIKit
class FeaturedAppsController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
let cellId = "cell"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
collectionView?.backgroundColor = .white
collectionView?.register(CategoryCell.self, forCellWithReuseIdentifier: cellId)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(view.frame.width, 150)
}
}
पूरे विवरण पाया जा सकता है और द्वारा विकसित किया गया था "चलो करने के लिए दिखाने उस ऐप का निर्माण ": https://www.youtube.com/watch?v=Ko9oNhlTwH0&list=PL0dzCUj1L5JEXct3-OV6itP7Kz3tRDmma
- 1. UICollectionViewCell को एनिमेटेड उपस्थिति को रोकना UICollectionView
- 2. UICollectionViewCell
- 3. UICollectionViewCell में ऑटो लेआउट
- 4. UICollectionView
- 5. UICollectionView
- 6. टीवीओएस: UICollectionViewCell
- 7. UICollectionView
- 8. UICollectionViewCell को यूआईबटन फोकस में टीवीओएस
- 9. 'UICollectionViewCell'
- 10. UICollectionViewCell
- 11. UICollectionViewCell
- 12. UICollectionViewCell छाया रंग
- 13. UICollectionViewCell का सबक्लास
- 14. UICollectionView
- 15. UICollectionView
- 16. UICollectionView
- 17. UICollectionView
- 18. UICollectionView
- 19. डिजाइनिंग UICollectionViewCell स्टोरीबोर्ड
- 20. UICollectionView CellForItemAtIndexPath सेल
- 21. UITableViewCell में एम्बेडेड UICollectionViewCell
- 22. बड़े UICollectionViewCell कस्टम लेआउट
- 23. UICollectionView रजिस्टर क्लास: forCellWithReuseIdentifier विधि UICollectionView
- 24. कस्टम UICollectionViewCell में UILabel हमेशा शून्य, पाठ
- 25. एक UICollectionView
- 26. UIImageView एनिमेटेड इस कोड के साथ UICollectionViewCell
- 27. सेल UICollectionView में नहीं दिख रहे हैं?
- 28. rac_signalForControlEvents UICollectionViewCell
- 29. UICollectionViewCell शेक
- 30. एक मौजूदा UICollectionView