UICollectionview为空

Nav*_*avi 3 storyboard nsarray ios uicollectionview uicollectionviewcell

嗨我创建了一个UIViewController,我添加了一个UICollectionViewCustomCell.然后,我uicollectionviewcell为细胞创建了一个类.最后在storybord本身设置委托和数据源.但它显示空页.如下图所示

在此输入图像描述

码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.collectionview = _collectionview;
    self.collectionview.dataSource = self;
    self.collectionview.delegate = self;

    speakersImages=[[NSMutableArray alloc]init];
    // Do any additional setup after loading the view, typically from a nib.
    imageLabels=[[NSMutableArray alloc]initWithObjects:@"RB Forum 2013",@"Agenda",@"Speakers",@"Contact",@"Map",@"Websites",@"@Responsible Biz",@"Partners",@"Sustainability",nil];


    imagePaths=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"RBform.png"],[UIImage imageNamed:@"agenda.png"],[UIImage imageNamed:@"speakers.png"],[UIImage imageNamed:@"contact.png"],[UIImage imageNamed:@"map.png"],[UIImage imageNamed:@"website.png"],[UIImage imageNamed:@"twitter.png"],[UIImage imageNamed:@"partners.png"],[UIImage imageNamed:@"sustainability.png"], nil];
    [self.collectionview registerClass:[NewCell class] forCellWithReuseIdentifier:@"Cell"];



}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
     numberOfItemsInSection:(NSInteger)section
{
    return [imageLabels count];
}

//THE BELOW DELEGATE METHOD DOES NOT GET CALLED!


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    // we're going to use a custom UICollectionViewCell, which will hold an image and its label
    //
    static NSString *CellIdentifier = @"Cell";
    NewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

    // make the cell's title the actual NSIndexPath value

    cell.labels.text = [NSString stringWithFormat:@"%@",[imageLabels objectAtIndex:indexPath.row]];
    // load the image for this cell
    NSLog(@"%@",imageLabels);
    //NSString *imageToLoad = [NSString stringWithFormat:@"%d.JPG", indexPath.row];
    //    cell.image.image = [UIImage imageNamed:imageToLoad];
    cell.images.image = [imagePaths objectAtIndex:indexPath.row];

    return cell;

}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

在此输入图像描述

在此输入图像描述

Nav*_*avi 22

解决方法是删除[self.collectionview registerClass:[NewCell class] forCellWithReuseIdentifier:@"Cell"];

在storybord我们不需要这个