2013-11-09 6 views
1

머리말 : 내 응용 프로그램의 iPad 레이아웃에서는 NSFetchedResultsController에서 제공하는 항목 ("PostCell")의 시작 부분에서 콜렉션보기 내에서 셀 ("PostAddCell")을 렌더링해야합니다. 이 셀은 새 항목을 만드는 데 사용됩니다. iPhone에서는 새 게시물을 추가하기위한 UI 단추가 필요하지 않습니다.UICollectionView가 셀을 표시하지 않습니다.

문제점 : PostAddCell은 NSFetchedResultsController에 결과가 없을 때만 나타납니다. 0

#pragma mark - UICollectionView Datasource 

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section 
{ 
    id <NSFetchedResultsSectionInfo> sectionInfo = [_fetch sections][section]; 
    if(isPad()){ 
     return [sectionInfo numberOfObjects]+1; 
    }else{ 
     return [sectionInfo numberOfObjects]; 
    } 
} 

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView 
{ 
    return [[_fetch sections] count]; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UICollectionViewCell *cell; 

    if(isPad()){ 
     if(indexPath.row == 0){ 
      cell = [cv dequeueReusableCellWithReuseIdentifier:@"PostAddCell" forIndexPath:indexPath]; 
      [(MNPAddPostCell*)cell configure]; 
     }else{ 
      NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section]; 
      cell = [cv dequeueReusableCellWithReuseIdentifier:@"PostCell" forIndexPath:newIndexPath]; 
      [(MNPPostCell*)cell configureForPost:[_fetch objectAtIndexPath:newIndexPath]]; 
     } 
    }else{ 
     cell = [cv dequeueReusableCellWithReuseIdentifier:@"PostCell" forIndexPath:indexPath]; 
     [(MNPPostCell*)cell configureForPost:[_fetch objectAtIndexPath:indexPath]]; 
    } 

    return cell; 

} 

답변

0

내 생각은 여기에 문제의 몇 가지가있다 : 수익 7을 가져 오는 경우 중단 점 및 로깅이 PostAddCell 인덱스 경로를 데이터 소스로 0을 반환되는 제안에도 불구하고, 내가 볼 모두 7 PostCells 있습니다. 먼저 섹션이 여러 개 있다고 가정하고 각 섹션의 행 0에 MNPAddPostCell을 표시하지 않으려면 인덱스 경로 행은 물론 인덱스 경로 행을 확인해야합니다. 둘째로 나는 생각한다

cell = [cv dequeueReusableCellWithReuseIdentifier:@"PostCell" forIndexPath:newIndexPath]; 

는 MNPAddPostCell을 쾅쾅 소리를 질렀다. 그것은

cell = [cv dequeueReusableCellWithReuseIdentifier:@"PostCell" forIndexPath:indexPath]; 

그냥 컨트롤러에서 올바른 개체를 가져 새 인덱스 경로를 사용해야하지?

+0

모든 섹션에서 행 0에 MNPAddPostCell이 필요합니다. PostCell이 PostAddCell 식별자를 어떻게 공격하는지 이해하지 못합니다. 바깥 쪽 블록은 iPad 용입니다. inner는 iPad 전용 행 확인이며 newIndexPath는 셀 생성이 존재하지 않는 행에 액세스하지 못하도록하기 위해 생성됩니다. –

+0

글쎄, 행 1에 대한 cellForItemAtIndexPath에 대해 반환하는 새 셀의 indexPath는 행 0에 대한 것이므로 UITableView가 원래 전달한 indexPath가 아닌 PostAddCell을 스톰핑하여 의미 한 것인지 궁금합니다. –

+0

/UITableView/UICollectionView : –

관련 문제