collectionView dequeueReusableCellWithIdentifier出错

时间:2013-04-16 13:40:26

标签: iphone ios ipad uicollectionview

我无法将uitable转换为collectionview。

我有以下代码,但它在“collectionView dequeueReusableCellWithIdentifier”上有错误我可以知道是什么问题吗?

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

//  Return the number of rows in the section (the amount of items in our array)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [pictureListData count];
}

//  Create / reuse a table cell and configure it for display
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UICollectionViewController *cell = [collectionView dequeueReusableCellWithIdentifier:CellIdentifier];


    // Get the core data object we need to use to populate this table cell
    Pictures *currentCell = [pictureListData objectAtIndex:indexPath.row];

1 个答案:

答案 0 :(得分:3)

您的方法名称错误。对于UICollectionViews,方法是:

- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath

所以你需要改变

UICollectionViewController *cell = [collectionView dequeueReusableCellWithIdentifier:CellIdentifier];

UICollectionViewController *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];