I am writing an iOS application. I have a CollectionView window and one customCell is added inside it by dragging it. When I launch the application, part of the CollectionView window is black. The collection reuse identifier is set to "ItemCell". The custom Cell view is set to the "CustomViewCell" class. CollectionView dataSource and delegate were configured on FirstViewController. This is the code:
FirstViewcontroller: #import <UIKit/UIKit.h> #import "CustomViewCell.h" @interface FirstViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate> @property (weak, nonatomic) IBOutlet UITextField *txtField; - (IBAction)slideRed:(id)sender; - (IBAction)slideGreen:(id)sender; - (IBAction)slideBlue:(id)sender; - (IBAction)btnAdd:(id)sender; @end
.m file:
#import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } -(void)viewDidAppear:(BOOL)animated { } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 10; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 5; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CustomViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ItemCell" forIndexPath:indexPath]; if (cell == nil) { cell = [[CustomViewCell alloc]init]; } cell.label.text = @"KitKat"; //cell.lblMain.textColor = [UIColor whiteColor]; // cell.backgroundColor = [UIColor blackColor]; return cell; } - (IBAction)slideRed:(id)sender { } - (IBAction)slideGreen:(id)sender { } - (IBAction)slideBlue:(id)sender { } - (IBAction)btnAdd:(id)sender { } @end
CustomViewCell:
#import "CustomViewCell.h" @implementation CustomViewCell @synthesize label; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) {
How to make this collectionView window display customCell with label. But this is just a black window. Best wishes
source share