2012-11-24 8 views
3

나는 내가 가지고있는 세포의 모든 행 후 UICollectionViewController.UICollectionView 헤더는 모든 행

UITableView 헤더 반복 서브 클래스 해요를 반복합니다. 헤더가 "싱글"이어야하며 항상 탐색 모음과 같은 화면 상단에 있어야합니다.

나는 다음과 같은 코드를 사용하고 있습니다 : 내 UICollectionViewController 클래스 :

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    return [categoryArray count]/2; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return 2; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CategoryCell" forIndexPath:indexPath]; 
    CategoryViewModel *category = [categoryArray objectAtIndex:(indexPath.section*2 + indexPath.row)]; 
    cell.name.text = category.name; 
    cell.image.image = category.image; 
    return cell; 
} 

-(UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ 
    if(headerIndexPath == nil){ 
     headerIndexPath = indexPath; 
    } 
    CategoryScreenHeader *categoryScreenHeader = [collectionView dequeueReusableSupplementaryViewOfKind: 
             UICollectionElementKindSectionHeader withReuseIdentifier:@"CategoryScreenHeader" forIndexPath:headerIndexPath]; 
    categoryScreenHeader.headerName.text = @"Some title"; 
    categoryScreenHeader.headerImage.image = [UIImage imageNamed:@"step-0.png"]; 
    return categoryScreenHeader; 
} 

당신을 감사합니다.

+0

어떤 레이아웃을 사용합니까? – chris

+0

나는 UICollectionViewLayout을 사용하고 있습니다. –

답변

0

UICollectionView에는 UITableView와 같은 테이블 헤더가 없습니다 (아는 한) 내용으로 스크롤하는 섹션 헤더 만 있습니다.

화면 상단의보기를 유지하려면 컨트롤러보기에 머리글과 모음 뷰용으로 2 개의 하위보기를 추가해야합니다. 컨트롤러의 기본보기가 아닌 하위보기로 컬렉션보기를 삽입하십시오. collectionView에있는 코드를 삭제합니다. viewForSupplementaryElementOfKind : atIndexPath : (섹션 헤더도 필요하지 않은 경우).

+0

감사합니다. 내 문제가 해결되었습니다! –