有两个实体(部门< - >> 员工)。
该部门有4名员工。当我获取此部门中的所有员工时,我的日志窗口显示:
CoreData:注释:总获取执行时间:4行为0.0017秒。
一切都很顺利。但UICollectionView
仅显示第一位员工4次。
例如:
Employee1,Employee1,Employee1,Employee1
而不是
Employee1,Employee2,Employee3,Employee4
我在 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;
}
提取后数组_ 是 NSMutableArray
答案 0 :(得分:4)
问题在索引方法中尝试此代码。
- (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;
}