cwRichardKim / RKSwipeCards

The basics of a swipeable card interface inspired by Tinder
MIT License
2.17k stars 61 forks source link

How can i make it endless loop ? #19

Closed kumararun540 closed 7 years ago

kumararun540 commented 9 years ago

I don't want to end the cards, how can i do that ?

I am doing like following but it looks like it repeats one time only after that end ?

Any suggestions ?

-(void)cardSwipedLeft:(UIView )card; { //do whatever you want with the card that was swiped // DraggableView c = (DraggableView *)card;

[loadedCards removeObjectAtIndex:0]; //%%% card was swiped, so it's no longer a "loaded card"

if (cardsLoadedIndex < [allCards count]) { //%%% if we haven't reached the end of all cards, put another into the loaded cards
    [loadedCards addObject:[allCards objectAtIndex:cardsLoadedIndex]];
    cardsLoadedIndex++;//%%% loaded a card, so have to increment count
    [self insertSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-1)] belowSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-2)]];
}

if (cardsLoadedIndex == [allCards count]) { cardsLoadedIndex = 0; loadedCards = [[NSMutableArray alloc] init]; allCards = [[NSMutableArray alloc] init]; [self loadCards]; } }

cwRichardKim commented 7 years ago

would recommend using a modulo (%) when indexing into the array, and don't remove the card from the array after swiping