18

मैं UICollectionView देखा here infinitive स्क्रॉलिंग को फिर से लागू करने की कोशिश कर रहा हूं। चीजें हैं जो मेरे लिए लापता गया:UICollectionView के बजाय एक ब्लैक स्क्रीन प्रदर्शित होती है

ViewController.h:

@interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate> 

@end 

DataCell.h:

@interface DataCell : UICollectionViewCell 
@property (nonatomic, strong) UILabel *label; 
@end 

DataCell.m:

#import "DataCell.h" 

@implementation DataCell 

-(instancetype)initWithFrame:(CGRect)frame { 
    self = [super initWithFrame:frame]; 
    if(self){ 
     self.label = [[UILabel alloc] initWithFrame:self.bounds]; 
     self.autoresizesSubviews = YES; 
     self.label.autoresizingMask = (UIViewAutoresizingFlexibleWidth | 
             UIViewAutoresizingFlexibleHeight); 
     self.label.textAlignment = NSTextAlignmentCenter; 
     self.label.adjustsFontSizeToFitWidth = YES; 

     [self addSubview:self.label]; 
    } 

    return self; 
} 

@end 

CustomCollectionView.h:

@interface CustomCollectionView : UICollectionView 

@end 

पूरी परियोजना मैं एक स्टोरीबोर्ड इस्तेमाल किया के लिए और एक सामान्य UIViewController। इस दृश्य नियंत्रक पर मैंने इंटरफ़ेस बिल्डर में UICollectionView जोड़ा। मैंने अपने व्यू कंट्रोलर के साथ संग्रह दृश्य से आउटलेट कनेक्ट किया है और मेरे व्यू कंट्रोलर को डेटासेट और प्रतिनिधि विधियों को फिर से स्थापित किया है। मैंने इंटरफेस बिल्डर में UICollectionViewCell और पुन: उपयोग पहचानकर्ता की कस्टम क्लास भी सेट की है।

तो सबकुछ काम करना चाहिए लेकिन मुझे केवल एक ब्लैक स्क्रीन मिलती है। मुझे क्या याद आ रहा है आप पूरी परियोजना here डाउनलोड कर सकते हैं।

उत्तर

23

आप सही ढंग से CollectionView कॉन्फ़िगर कर रहे हैं, सिर्फ इतना है कि आप लेबल :) का रंग

[self.label setTextColor:[UIColor whiteColor]]; 

enter image description here

आशा है कि यह मदद करता है भूल गया!

4

मुझे एक ही समस्या थी। ब्लैक स्क्रीन प्रदर्शित करने के लिए संग्रह दृश्य के साथ उपलब्ध कोई डेटा का सूचक नहीं प्रतीत होता है। संग्रह दृश्य के पृष्ठभूमि रंग को बदलने का प्रयास करें, अगर उस रंग को प्रदर्शित करने के लिए रंग बदल गया है, तो आपका संग्रह दृश्य काम कर रहा है। और फिर टैग के साथ संग्रह दृश्य में कुछ छविदृश्य जोड़ें (उदा। छवि दृश्य के लिए टैग मान के साथ एक मान 100 दें) और cellforItemAtIndexPath छवियों को छवि दृश्य में सेट करें। (आप कस्टम सेल के साथ ऐसा कर सकते हैं। लेकिन अब के लिए, संग्रह दृश्य काम, imageView सूट बेहतर करने के लिए टैग के साथ काम पाने के लिए)

UIImageView * ImageView = (UIImageView *)[cell viewWithTag:100]; 
ImageView.image = [UIImage imageNamed:[images objectAtIndex:indexPath.row]]; 
3

आप मैन्युअल संग्रह को देखने की पृष्ठभूमि का रंग निर्धारित करने की आवश्यकता स्टोरीबोर्ड में।

डिफ़ॉल्ट रूप से यह काला है (हालांकि नहीं दिखाई दे रहा है कि स्टोरीबोर्ड संपादक में)

enter image description here

+0

यदि आप पृष्ठभूमि को बंद करना चाहते हैं कान, आपको 'collectionView.backgroundColor = [UIColor clearColor];' और 'collectionView का उपयोग करना होगा।backgroundView = [[UIView alloc] initWithFrame: CGRectZero]; ' – Multinerd

1

स्विफ्ट में,

self.label.textColor = UIColor.whiteColor() 
0
[self.collectionView registerNib:[UINib nibWithNibName:@"ProductCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ProductCollectionViewCell"]; 

self.collectionView.backgroundColor = [UIColor clearColor]; 
1

यह मेरे लिए हुआ है कि दोनों collectionView और संग्रह दृश्य कक्ष में पारदर्शी पृष्ठभूमि

संबंधित मुद्दे