Ios UICollectionView在没有情节提要的情况下无法工作

Ios UICollectionView在没有情节提要的情况下无法工作,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,您好,我已经创建了UICollectionViewCell的nib,并设置了标识符“gridcell”。我正在使用以下代码,但正在引发异常。这是我的密码: @implementation PhotosView -(void)configureView:(id)object { event=object; [collectionView registerClass:[PhotosCollectionViewCell class] forCellWithReu

您好,我已经创建了UICollectionViewCell的nib,并设置了标识符“gridcell”。我正在使用以下代码,但正在引发异常。这是我的密码:

@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

像这样:

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

在您的-configureView:method中,使用-registernb:而不是-registerClass:这对我绝对有帮助!谢谢
    [self.yourCollectionView registerNib:[UINib nibWithNibName:@"PhotosCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"gridcell"];