I'm using iCarousel in my Swift+Sprite Kit game, where the user has unlocked and locked items.
The locked items would display some info like current user coins, and some text that says "UNLOCK THIS FOR: X amount of coins", if the carousel item isn't locked, it won't display any of that information, just a button that says "Select".
Now, I got that working, but it will only work when i start swiping the items and not the first time the carousel shows up.
To make that work, I do it inside carouselCurrentItemIndexDidChange() method. And that obviously changes when I swipe.
How can I set the current carousel index at start so then I can force to show or not show the information depending if the item is locked or unlocked and not only when I start swiping?
To add more information about this, imagine that the user selected the item at index 4, i save that index locally. So if the user closes and opens the game, the carousel should begin at 4 not 0.
Thanks in advance.
viewForItemAtIndex
, not the delegate method you are using – Paulw11cellForRowAtIndexPath
; when views scroll of screen they are discarded and retrieved from this method when they come back onto the screen. If there is a change to the underlying data that affects a view you can callreloadItemAtIndex
and then the carousel view will callviewForItemAtIndex
to get the updated view. – Paulw11viewForItemAtIndex
I was just saving typing. The full name is the method you said,viewForItemAtIndex: reusingView:
. To start from item 4, you would callscrollToItemAtIndex:animated:
probably somewhere likeviewWillAppear
– Paulw11