Iglistkit: About UICollectionView dequeueReusableCellWithReuseIdentifier

Created on 16 May 2018  路  5Comments  路  Source: Instagram/IGListKit

When MyCollectionViewCell has two different cell reuseIdentifier, IGListKit unable to auto register two different cell reuseIdentifier cell class.

- (__kindof UICollectionViewCell *)dequeueReusableCellOfClass:(Class)cellClass
                                 withReuseIdentifier:(NSString *)reuseIdentifier
                                forSectionController:(IGListSectionController *)sectionController
                                             atIndex:(NSInteger)index {
   ......

     // One cell class only cloud be registered once
    if (![self.registeredCellClasses containsObject:cellClass]) {
        [self.registeredCellClasses addObject:cellClass];
        [collectionView registerClass:cellClass forCellWithReuseIdentifier:identifier];
    }


    return [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
}

How to solve this problem? (sorry for my bad english.)

question

Most helpful comment

I know that method, but the implementation of that method is the issues codes.

// One cell class only cloud be registered once
    if (![self.registeredCellClasses containsObject:cellClass]) {
        [self.registeredCellClasses addObject:cellClass];
        [collectionView registerClass:cellClass forCellWithReuseIdentifier:identifier];
    }

All 5 comments

@devcxm if you use the latest version of IGListKit, you鈥檒l notice that there is a new dequeue method with a reuseIdentifier parameter that will allow you to do just that!

Does that answer your question?

Sent with GitHawk

I know that method, but the implementation of that method is the issues codes.

// One cell class only cloud be registered once
    if (![self.registeredCellClasses containsObject:cellClass]) {
        [self.registeredCellClasses addObject:cellClass];
        [collectionView registerClass:cellClass forCellWithReuseIdentifier:identifier];
    }

I think I know the problem here.
in that method, you set identifier with combination of reuseIdentifier and cellClass

    NSString *identifier = IGListReusableViewIdentifier(cellClass, nil, nil, reuseIdentifier);

but, registeredCellClasses store cellClass as unique key, not considering reuseIdentifier.

    if (![self.registeredCellClasses containsObject:cellClass]) {

For example, I want to register a class (let say ClassX) with two different reuse identifiers (id1 and id2). Class ClassX is registered successfully with first identifier (id1ClassX). But for second identifier (id2ClassX), it will be crash since registeredCellClasses already contains ClassX and try to reuse with second identifier, but none exist for that identifier.

I knew the cause of the problem, so I fork to https://gitee.com/cxmapp/IGListKit and fix the problem.

Closing this since the issue has been fixed.

Was this page helpful?
0 / 5 - 0 ratings