समस्या यह है कि संग्रह दृश्य में कॉलम की संख्या घूर्णन पर 7 (वांछित राशि) पर नहीं रहती है। इसे ठीक करने के लिए किस कोड परिवर्तन की आवश्यकता है?अमान्य क्यों है Layout आकार ट्रिगर नहीं कर रहा है UICollectionView मेंForItemAtIndexPath? (कोड संलग्न)
ऐसा लगता है कि कस्टम UICollectionViewFlowLayout से अवैध है Layout आकार दृश्य में ForItemAtIndexPath विधि को ट्रिगर नहीं कर रहा है? कोई विचार? मैं वास्तव में रोटेशन पर आकारफोरमेट इंडेक्सपैथ आकार के माध्यम से कॉलम का आकार बदलना चाहता हूं।
नोट: मैं यहां स्टोरीबोर्ड का उपयोग नहीं कर रहा हूं, बल्कि मेरे पास एक कस्टम दृश्य है जिसमें मैं संग्रह में ड्रॉप करता हूं और अपने स्वयं के संग्रह दृश्य वर्गों का संदर्भ देता हूं।
निम्न कोड ठीक काम करता है, हालांकि घूर्णन पर यह स्तंभों की संख्या को 7 तक नहीं रखता है।
GCCalendar - init coder
GCCalendar - commonInit
GCCalendarLayout:invalidateLayout
GCCalendarLayout:invalidateLayout
ViewController:viewWillLayoutSubviews
GCCalendarLayout:invalidateLayout
GCCalendarLayout:prepareLayout
sizeForItemAtIndexPath
.
.
sizeForItemAtIndexPath
minimumInteritemSpacingForSectionAtIndex
minimumLineSpacingForSectionAtIndex
GCCalendarLayout:collectionViewContentSize
GCCalendarLayout:layoutAttributesForElementsInRect
GCCalendarLayout:collectionViewContentSize
ViewController:viewWillLayoutSubviews
GCCalendarCell:drawRect
.
.
GCCalendarCell:drawRect
हालांकि उसके बाद स्क्रीन मैं निम्न देखें घूर्णन: कोड शुरू में कंसोल आउटपुट शो चल रहा है पर
ViewController:viewWillLayoutSubviews
GCCalendarLayout:shouldInvalidateLayoutForBoundsChange
GCCalendarLayout:invalidateLayout
GCCalendarLayout:prepareLayout
GCCalendarLayout:collectionViewContentSize
GCCalendarLayout:layoutAttributesForElementsInRect
GCCalendarLayout:collectionViewContentSize
तो इस मुद्दे को कभी नहीं बुलाया गया "sizeForItemAtIndexPath" है ????
रोटेशन पर आउटपुट कोड
नोट: viewWillLayoutSubviews GCCalendarLayout: shouldInvalidateLayoutForBoundsChange GCCalendarLayout:
invalidateLayout "sizeForItemAtIndexPath" यहाँ तक कि "invalidateLayout" हालांकि ट्रिगर नहीं हैViewController है
** मेरा कस्टम कि घरों संग्रह देखें देखें **
import UIKit @IBDesignable class GCCalendarView: UIView { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonInit() } override init(frame: CGRect) { super.init(frame: frame) commonInit() } // Private private func commonInit() { if self.subviews.count == 0 { let bundle = NSBundle(forClass: self.dynamicType) let nib = UINib(nibName: "GCCalendarView", bundle: bundle) let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView view.frame = bounds view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] addSubview(view) } } }
कस्टम संग्रह देखें
import UIKit class GCCalendar : UICollectionView, UICollectionViewDataSource, UICollectionViewDelegate { // Init --------------- func commonInit(coder aDecoder: NSCoder) { print("GCCalendar - commonInit") self.registerClass(GCCalendarCell.self, forCellWithReuseIdentifier: "GCCalendarCell") self.dataSource = self self.delegate = self let layout : GCCalendarLayout = GCCalendarLayout(coder: aDecoder)! self.setCollectionViewLayout(layout, animated: false) self.backgroundColor = UIColor.whiteColor() } required init?(coder aDecoder: NSCoder) { print("GCCalendar - init coder") super.init(coder: aDecoder) commonInit(coder: aDecoder) } // UICollectionViewDelegateFlowLayout ------------ func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { print("sizeForItemAtIndexPath") let w : CGFloat = floor(self.frame.size.width/7) return CGSize(width: w, height: w) } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { print("minimumInteritemSpacingForSectionAtIndex") return 0.0 } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { print("minimumLineSpacingForSectionAtIndex") return 0.0 } // UICollectionViewDataSource ------------------- func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 21 } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("GCCalendarCell", forIndexPath: indexPath) as? GCCalendarCell return cell! } }
** कस्टम CollectionView सेल **
import UIKit class GCCalendarCell: UICollectionViewCell { @IBOutlet weak var title : UITextField! @IBOutlet weak var date: UILabel! required init?(coder aDecoder: NSCoder) { print("GCCalendarCell - init:coder") super.init(coder: aDecoder) commonInit() } override init(frame: CGRect) { super.init(frame: frame) commonInit() } override func drawRect(rect: CGRect) { print("GCCalendarCell:drawRect") self.layer.borderWidth = 1 self.layer.borderColor = UIColor.grayColor().CGColor } // Private private func commonInit() { let bundle = NSBundle(forClass: self.dynamicType) let nib = UINib(nibName: "GCCalendarCell", bundle: bundle) let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView view.frame = bounds view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] addSubview(view) } }
कस्टम लेआउट
import UIKit class GCCalendarLayout : UICollectionViewFlowLayout { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { print("GCCalendarLayout:shouldInvalidateLayoutForBoundsChange") return true } override func invalidateLayout() { print("GCCalendarLayout:invalidateLayout") super.invalidateLayout() } override func prepareForCollectionViewUpdates(updateItems: [UICollectionViewUpdateItem]) { print("GCCalendarLayout:prepareForCollectionViewUpdates") super.prepareForCollectionViewUpdates(updateItems) } override func finalizeCollectionViewUpdates() { print("GCCalendarLayout:finalizeCollectionViewUpdates") super.finalizeCollectionViewUpdates() } }
आप स्टोरीबोर्ड –
का उपयोग कर रहे हैं। स्टोरीबोर्ड – Greg
का उपयोग नहीं कर रहा हूं, मैं आपकी मदद कर सकता हूं लेकिन मुझे तेज़ी से पता नहीं है। क्या आप obj-c पढ़ सकते हैं? – Kujey