2014-04-13 4 views
0

안녕하세요 저는 UICollectionViewCell의 펜촉을 만들고 식별자 "gridcell"을 설정했습니다. 다음 코드를 사용하고 있지만 예외를 throw하고 있습니다. 여기 내 코드입니다 :스토리 보드없이 UICollectionView가 작동하지 않습니다.

@implementation PhotosView 
-(void)configureView:(id)object 
{ 
    event=object; 
    [collectionView registerClass:[PhotosCollectionViewCell class] 
      forCellWithReuseIdentifier:@"gridcell"]; 

    if (photos.count<1) { 

     NSString* url=[NSString stringWithFormat:@"%@getImage/%d.json",kBaseURL,[event.eventId intValue]]; 
     [self sendHttpPostJsonRequestWith:url jsonData:nil andRequestId:100]; 

    } 
} 

-(void)didReceiveData:(NSData *)data error:(NSError *)error andRequestId:(int)requestId 
{ 
    if (data) { 
     photos=[PhotosParser parseRoot:data]; 
     [collectionView reloadData]; 
    } 
} 

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 

    return 1; 
} 

-(UICollectionViewCell *)collectionView:(UICollectionView *)aCollectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    PhotosCollectionViewCell *cell=[aCollectionView dequeueReusableCellWithReuseIdentifier:@"gridcell" forIndexPath:indexPath]; 

    return cell; 

} 

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

@end 

그리고 다음과 같은 오류입니다 : 당신은 너무처럼 viewDidLoad

먼저 사용자 정의 셀을 등록해야

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier gridcell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' 
+0

당신의 -configureView : 메소드, 사용 -registerNib : 대신 -registerClass : –

답변

1

:에서

[self.yourCollectionView registerNib:[UINib nibWithNibName:@"PhotosCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"gridcell"]; 
+0

이것은 분명히 나를 도왔습니다! 감사. – Zolnoor

관련 문제