5

2つのエンティティがあります(部門<->>従業員)。

この部門には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;
}

array_はフェッチ後のNSMutableArrayです

4

1 に答える 1

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;
}
于 2013-02-28T09:01:28.713 に答える