2015-01-07 5 views
1

UICollection 뷰에 동적 CellIdentifier 이 있어야합니다.동적 셀 식별자가있는 UICollectionView

NSString *strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",indexPath.row]; 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:strIdentifier forIndexPath:indexPath]; 

어떻게하면됩니까? 가능하다면 도와주세요 !!! 감사

이 코드

//CollectionView 
    self.mpCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:layout]; 
    [self.mpCollectionView setDataSource:self]; 
    [self.mpCollectionView setDelegate:self]; 
    for(int i=0;i<arrayExplorerItems.count;i++) 
    { 
     NSString* strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",i]; 
     NSLog(@"registered Id:%@",strIdentifier); 
     [self.mpCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:strIdentifier]; 
    } 

and my cellForItemAtIndeaxPath is 

    UICollectionViewCell *cell; 
    NSString *strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",indexPath.row]; 
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:strIdentifier forIndexPath:indexPath]; 

모든 내 식별자를 등록

EDIT하지만 날이 오류를 제공

가지보기 큐에서 제거 할 수 없습니다 : UICollectionElementKindCell 식별자 cellIdentifier0과를 -해야 식별자에 펜촉이나 클래스를 등록하거나 스토리 보드에 프로토 타입 셀을 연결하십시오 '

+0

/언제 레지스터 코드 루프를 실행합니까? – rounak

+0

collectionview를 할당 한 직후 – Anand

+0

cellForItem을 호출하기 전에 NSLog를 등록하려고합니까? – rounak

답변

1

가능합니다. 먼저 모든 셀 식별자를 등록해야합니다.

[collectionView registerNib:forCellWithReuseIdentifier:] 

또는

[collectionView registerClass:forCellWithReuseIdentifier:] 

그런 다음 생성하고 문제없이 모든 준비 식별자를 큐에서 할 수 있습니다.

+0

다른 식별자를 등록하는 방법은? – Anand

+0

더 많은 코드와 오류에 대한 내 질문을보십시오. – Anand