cwRichardKim / RKSwipeCards

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

Load all images from NSArray #11

Closed datomnurdin closed 9 years ago

datomnurdin commented 9 years ago

How to load all images from NSArray into this code?

exampleCardLabels = [[NSArray alloc]initWithObjects:
         [UIImage imageNamed:@"first.jpg"],
         [UIImage imageNamed:@"second.jpg"],
         [UIImage imageNamed:@"third.jpg"],
         [UIImage imageNamed:@"fourth.jpg"],
         [UIImage imageNamed:@"fifth.jpg"],nil];

-(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index
{
    DraggableView *draggableView = [[DraggableView alloc]initWithFrame:CGRectMake((self.frame.size.width - CARD_WIDTH)/2, (self.frame.size.height - CARD_HEIGHT)/3, CARD_WIDTH, CARD_HEIGHT)];
    draggableView.information.text = [exampleCardLabels objectAtIndex:index]; //%%% placeholder for card-specific information
    draggableView.delegate = self;
    return draggableView;
}

//%%% loads all the cards and puts the first x in the "loaded cards" array
-(void)loadCards
{
    if([exampleCardLabels count] > 0) {
        NSInteger numLoadedCardsCap =(([exampleCardLabels count] > MAX_BUFFER_SIZE)?MAX_BUFFER_SIZE:[exampleCardLabels count]);
        //%%% if the buffer size is greater than the data size, there will be an array error, so this makes sure that doesn't happen

        //%%% loops through the exampleCardsLabels array to create a card for each label.  This should be customized by removing "exampleCardLabels" with your own array of data
        for (int i = 0; i<[exampleCardLabels count]; i++) {
            DraggableView* newCard = [self createDraggableViewWithDataAtIndex:i];
            [allCards addObject:newCard];

            if (i<numLoadedCardsCap) {
                //%%% adds a small number of cards to be loaded
                [loadedCards addObject:newCard];
            }
        }

        //%%% displays the small number of loaded cards dictated by MAX_BUFFER_SIZE so that not all the cards
        // are showing at once and clogging a ton of data
        for (int i = 0; i<[loadedCards count]; i++) {
            if (i>0) {
                [self insertSubview:[loadedCards objectAtIndex:i] belowSubview:[loadedCards objectAtIndex:i-1]];
            } else {
                [self addSubview:[loadedCards objectAtIndex:i]];
            }
            cardsLoadedIndex++; //%%% we loaded a card into loaded cards, so we have to increment
        }
    }
}
cwRichardKim commented 9 years ago

Hey, I'm sorry I dropped the ball on responding to you. Did you manage to figure this out?

ibata commented 9 years ago

I am intestered. Can someone please answer? How to load all images from NSArray into this code?

exampleCardLabels = [[NSArray alloc]initWithObjects: [UIImage imageNamed:@"first.jpg"], [UIImage imageNamed:@"second.jpg"], [UIImage imageNamed:@"third.jpg"], [UIImage imageNamed:@"fourth.jpg"], [UIImage imageNamed:@"fifth.jpg"],nil];

-(DraggableView )createDraggableViewWithDataAtIndex:(NSInteger)index { DraggableView draggableView = [[DraggableView alloc]initWithFrame:CGRectMake((self.frame.size.width - CARD_WIDTH)/2, (self.frame.size.height - CARD_HEIGHT)/3, CARD_WIDTH, CARD_HEIGHT)]; draggableView.information.text = [exampleCardLabels objectAtIndex:index]; //%%% placeholder for card-specific information draggableView.delegate = self; return draggableView; }

//%%% loads all the cards and puts the first x in the "loaded cards" array -(void)l

cwRichardKim commented 9 years ago

Its not very clear what exactly you're asking. Where are you getting the images from? What do you mean by "load"? Do you mean into an array or from the array onto cards?

datomnurdin commented 9 years ago

I'm still can't figure out until now.

ibata commented 9 years ago

I have the same issue than reported on the original issue by the other folk.

The code shows labels first , two etc. I want to use local pictures for instance how should edit the code?

Luc Ibata LinkedIn.com/in/lucibata "Follow your dream"

On May 9, 2015, at 9:36 AM, datomnurdin notifications@github.com wrote:

I'm still can't figure out until now.

— Reply to this email directly or view it on GitHub.

cwRichardKim commented 9 years ago

Ok, so the best I can do (short of actually writing the code for you), is recommend that you guys take the time to read and understand the code before you move on. How do the labels work? Well, I added a UILabel to the draggable view, and then supplied each with information from an array in draggableBackgroundView. So, if the array has ["hello", "two", "goodbye"] then the first card will have "hello", the second card will have "two", and the third card will have "goodbye".

Once you understand how that works, you'll understand how to do the same thing with photos. Just to get you on the right track, here's a general guideline: 1) add a UIImageView to DraggableView as a placeholder for where you want the images to be 2) create an array of the images you want (either download them or grab them locally) 3) set the draggableView.imageView.image = imageArray[indexOfCard]; <-- do not copy and paste that, it's pseudo code, not literal code