2

I just started programming with Swift a few months ago so to help me learn, I'm working on a project similar to Tinder using Koloda View. I'm using Firebase as my backend. The code I have included below works fine with 6 images assets of cards but I'm trying to figure out a way to create a card for each user and use these custom cards as the data source for the KolodaView.

I created a XIB file to use as a template for these cards but I'm not sure how I can get information from each user in my database to display on these cards. Also, how do I instantiate multiple copies of the XIB file to use for each user?

Sorry for the confusing wording of the question since I am just a beginner I'm having trouble trying to articulate my problem. Please ask me if you need any clarification on what I'm trying to say.

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.
    }

    //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
    }
}
mugx
  • 9,869
  • 3
  • 43
  • 55
A. Albert
  • 65
  • 8

0 Answers0