머리말 : 내 응용 프로그램의 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에 MNPAddPostCell이 필요합니다. PostCell이 PostAddCell 식별자를 어떻게 공격하는지 이해하지 못합니다. 바깥 쪽 블록은 iPad 용입니다. inner는 iPad 전용 행 확인이며 newIndexPath는 셀 생성이 존재하지 않는 행에 액세스하지 못하도록하기 위해 생성됩니다. –
글쎄, 행 1에 대한 cellForItemAtIndexPath에 대해 반환하는 새 셀의 indexPath는 행 0에 대한 것이므로 UITableView가 원래 전달한 indexPath가 아닌 PostAddCell을 스톰핑하여 의미 한 것인지 궁금합니다. –
/UITableView/UICollectionView : –