I have an application with a UIViewController with a UICollectionView IBOutlet in it.



The cell in the UICollectionView is MyCustomCell and this method sets the UILabel:
-(void)setCellLabel:(NSString *)value{ NSLog(@"settinglabel"); cellLabel.text = @"hardcode";
A cell has a class property that identifies it as MyCustomCell in the storyboard and its detection identifier. UIViewController accepts data and delegation protocols. IBUutlet UILabel has a CellLabel output connected to the storyboard. Methods are defined as:
- (void)viewDidLoad{ [super viewDidLoad]; self.restNames = @[@"Orange",@"Naranja",@"Narnia"]; [self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"MyCustomCellID"]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ NSLog(@"%d",[self.restNames count]); return [self.restNames count]; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ MyCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; [cell setCellLabel:@"hi"]; NSLog(@"fitsname %@",[self.restNames objectAtIndex:indexPath.row]); return cell; }
I get three cells drawn in my table view, corresponding to 3 objects in my array. The array simply contains the string objects that I installed directly with objectAtIndexPath, but I decided to set it directly to "hi" since it did not work. I even changed the value used in the setCellLabel method to a solid value, and I save only the default label string in each cell.
Why is the cell cell not set correctly?
ios uicollectionviewcell
marciokoko
source share