There are two entities (Department <-->> Employee).
There are 4 employees in this department. When I fetch all Employees in this Department my log window show:
CoreData: annotation: total fetch execution time: 0.0017s for 4 rows.
everything well.
But UICollectionView
displays only first employee for 4 times.
For example:
Employee1, Employee1, Employee1, Employee1
instead of
Employee1, Employee2, Employee3, Employee4
I thing there is some mistake in cellForItemAtIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cellRecipe";
collectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
Employee *emp = [array_ objectAtIndex:indexPath.item];
cell.name.text = emp.name;
cell.image.image = emp.thumbImg;
return cell;
}
array_ is a NSMutableArray after fetch
Problem is in the indexing method try this code.
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return noOfItem/ noOfSection;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return noOfSection;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cellRecipe";
collectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
;
Employee *emp = [array_ objectAtIndex:indexPath.section * noOfSection + indexPath.row];
cell.name.text = emp.name;
cell.image.image = emp.thumbImg;
return cell;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With