Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Koloda library with Parse data source

I'm using Koloda library (https://github.com/Yalantis/Koloda) to display data in swipe views Tinder like cards.

import UIKit
import Koloda
import pop
import Parse
import Bolts
import ParseUI

private var numberOfCards: UInt = 5


class ViewController: UIViewController, KolodaViewDataSource,     KolodaViewDelegate {

    var ids : [String] = []

    @IBOutlet weak var kolodaView: KolodaView!
    @IBAction func undo(sender: AnyObject) {
        kolodaView?.revertAction()

    }

    @IBAction func left(sender: AnyObject) {
        kolodaView?.swipe(SwipeResultDirection.Left)

    }

    @IBAction func right(sender: AnyObject) {
        kolodaView?.swipe(SwipeResultDirection.Right)

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        kolodaView.dataSource = self
        kolodaView.delegate = self

        self.modalTransitionStyle =  UIModalTransitionStyle.FlipHorizontal
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK: KolodaViewDataSource


    func kolodaNumberOfCards(koloda: KolodaView) -> UInt {
        return numberOfCards
    }

    func kolodaViewForCardAtIndex(koloda: KolodaView, index: UInt) ->  UIView {
        return UIImageView(image: UIImage(named: "Card_like_\(index + 1)"))

    }

    func kolodaViewForCardOverlayAtIndex(koloda: KolodaView, index: UInt) -> OverlayView? {
        return NSBundle.mainBundle().loadNibNamed("OverlayView",
            owner: self, options: nil)[0] as? OverlayView
    }

    //MARK: KolodaViewDelegate

    func kolodaDidSwipedCardAtIndex(koloda: KolodaView, index: UInt,  direction: SwipeResultDirection) {
        //Example: loading more cards
        if index >= 3 {
            numberOfCards = 6
            kolodaView.reloadData()
        }
    }

    func kolodaDidRunOutOfCards(koloda: KolodaView) {
        //Example: reloading
        kolodaView.resetCurrentCardNumber()
    }

    func kolodaDidSelectCardAtIndex(koloda: KolodaView, index: UInt) {
        UIApplication.sharedApplication().openURL(NSURL(string: "http://yalantis.com/")!)
    }

    func kolodaShouldApplyAppearAnimation(koloda: KolodaView) -> Bool {
        return true
    }

    func kolodaShouldMoveBackgroundCard(koloda: KolodaView) -> Bool {
        return true
    }

    func kolodaShouldTransparentizeNextCard(koloda: KolodaView) -> Bool {
        return true
    }

    func kolodaBackgroundCardAnimation(koloda: KolodaView) -> POPPropertyAnimation? {
        return nil
    }
}

The above code works fine with the six images I have stored in Assets. What I want is to fill every card with data from a ParseUser (Text and a image). I've been thinking about something similar of filling a tableView with ParseData but I can't find the correct solution. This is the purpose of KolodaView:

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. It adds convenient functionality such as a UITableView-style dataSource/delegate interface for loading views dynamically, and efficient view loading, unloading .

Maybe there is another library to do the same.

like image 394
Joan Marc Sanahuja Avatar asked Dec 30 '25 20:12

Joan Marc Sanahuja


1 Answers

You can use Koloda in the same way as UITableView. Start fetching objects in viewDidLoad asynchronously and then call reloadData in callback, so Koloda has to reconfigure its views.

Note: There is networking_example in repository https://github.com/Yalantis/Koloda/tree/networking_example

like image 77
Eugene Andreyev Avatar answered Jan 02 '26 12:01

Eugene Andreyev