5

यह एक साधारण सवाल है कि मैंने सोचा कि एक आसान जवाब मिल जाएगा लेकिन नहीं। मैं संग्रहदृश्य में एक सेल का चयन करना चाहता हूं। मुख्य समस्या यह है कि मैं एक प्रोटोटाइप सेल में एक इशारा पहचानकर्ता संलग्न नहीं कर सकता। मैं स्पर्श किए गए सेल पर एक लेबल से पाठ को पकड़ना चाहता हूं। मैं अपने विचार में एक अलग समारोह में नाम का उपयोग करता हूं।मुझे चयनित संग्रहदृश्य का नाम कैसे प्राप्त होगा?

या एक आसान सवाल: क्या वस्तुओं की सूची से टैप चयन पर कोई ट्यूटोरियल है?

उत्तर

6

आपके पास प्रतिनिधि में collectionView:didSelectItemAtIndexPath: विधि है। जब आप सेल एकत्र करते हैं और उस विशेष सेल के लिए आपको सही इंडेक्सपैथ देते हैं तो यह आग लगनी चाहिए।

किसी विशेष सेल तक पहुंचने के लिए संग्रहView के cellForItemAtIndexPath: के साथ संयोजन में इस अनुक्रमणिका का उपयोग करें।

उदाहरण:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 
    [self manipulateCellAtIndexPath:indexPath]; 
} 

-(void) manipulateCellAtIndexPath:(NSIndexPath*)indexPath { 
    UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; 
    // Now do what you want... 
} 

और, जब तक मैं यहाँ हूँ के रूप में। स्विफ्ट संस्करण:

override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) { 
    manipulateCellAtIndexPath(indexPath) 
} 

func manipulateCellAtIndexPath(indexPath: NSIndexPath) { 
    if let cell = collectionView?.cellForItemAtIndexPath(indexPath) { 
     // manipulate cell 
    } 
} 
संबंधित मुद्दे