Vishal-Singh-Panwar / InfiniteScrolling

Add infinite scrolling to collection view.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indexpath is returning wrong

Pinank opened this issue · comments

I have 10 fix indexpaths and on each indexpath it should diff. color and image. So i've place a conditional block in following method

func configuredCell(forItemAtIndexPath indexPath: IndexPath, originalIndex: Int, andData data:     InfiniteScollingData, forInfiniteScrollingBehaviour behaviour: InfiniteScrollingBehaviour) -> UICollectionViewCell { }

But its not returning the correct indexpath. Can any1 from here help me to out

Use originalIndex and let me know if it works.

Its Not, Its getting fluctuated in start like from 0-5 or 0-1 and 1-2.

originalIndex is an Int. It can't be in IndexPath format like 0-5. Can you share the line where you are setting color?

I know its Int, with 0-5 mean to say from 0th index to reverse scroll 5th index. Suppose in following manner my cells are,

0-1-2-3-4-5

and i want it to be in,

0-1-2-3-4-5-0-1-2-3-4-5-0-1-2-3-4-5-0-1-2-3-4-5...

but when i move from 0 to 5 or 5 to 0 or from 1 to 2, its not returning the exact index value

I am not getting you. Can you share the code?

In my case, at a time only one cell will be visible.

you have a UICollectionView inside UICollectionViewCell?

Yes, But i think it should not affect

You are updating your collectionViewCell based on roomData.index. Not sure how it is related to index provided by configuredCell method. I might need some more clarity on the issue. I think when the parent cell is reused, you are loosing the previously visible room in your child collection view. Is that your issue?

Corrected

func configuredCell(forItemAtIndexPath indexPath: IndexPath, originalIndex: Int, andData data: InfiniteScollingData, forInfiniteScrollingBehaviour behaviour: InfiniteScrollingBehaviour) -> UICollectionViewCell {

    let cell = cvItems.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
    cell.collectionviewRoomItemList!.register(UINib(nibName: "testCell", bundle: nil), forCellWithReuseIdentifier: "testCell")

    print("--------------->",originalIndex )
        switch originalIndex {
        case 1:

            break

        case 2:

            break

        case 3:

            break

        case 4:

            break

        case 5:

            break

        case 6:

            break

        default:
            break
        }
    cell.cvItems.reloadData()
    return cell
}

Solved