When working on UICollectionView, I am loading a cell from nib like below
And my nib file looks like the first image below
The top label is used to displayed the number of cell and the middle label is used to display a certain text
in method cellForItemAtIndexPath, I just want to set the text to the cell of certain row ( in this example, I am doing it at row of 1 ) :
When running the app, there is a problem on it. Not only is titleLabel of cell at row1 set to This is row 1, but also the titleLabel of row5 and row9 and row10 is set as well. The second and third + fourth are illustration.
If anybody knows what I am doing wrong in the middle. please help.
My colleciton is containing 1 section and 15 row for this section.
Code:
(void)viewDidLoad
{
[super viewDidLoad];
/* Uncomment this block to use nib-based cells */
UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];
// Configure layout
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
self.collectionView.contentInset = UIEdgeInsetsMake(10.0f, 0.0f, 10.0f, 0.0f);
[flowLayout setItemSize:CGSizeMake(300, 200)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.collectionView setCollectionViewLayout:flowLayout];
}
The top label is used to displayed the number of cell and the middle label is used to display a certain text
in method cellForItemAtIndexPath, I just want to set the text to the cell of certain row ( in this example, I am doing it at row of 1 ) :
Code:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell identifier
static NSString *cellIdentifier = @"cvCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
UILabel *cellLablel = (UILabel *)[cell viewWithTag:200];
cellLablel.text = self.dataArray[0][indexPath.row];
if ( indexPath.row == 1)
[titleLabel setText:@"this is row 1"];
return cell;
}
If anybody knows what I am doing wrong in the middle. please help.
My colleciton is containing 1 section and 15 row for this section.