使用具有Parse数据源的Koloda库

时间:2015-10-12 09:02:50

标签: ios swift parse-platform swift2 swipe

我使用Koloda图书馆(https://github.com/Yalantis/Koloda)在滑动视图中显示Tinder卡片等数据。

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

以上代码适用于我存储在Assets中的六张图片。我想要的是用ParseUser(文本和图像)中的数据填充每张卡片。我一直在考虑用ParseData填充tableView,但我无法找到正确的解决方案。这是KolodaView的目的:

  

KolodaView是一个旨在简化iOS上Tinder卡的实现的课程。它增加了方便的功能,例如UITableView样式的dataSource / delegate接口,用于动态加载视图,以及高效的视图加载,卸载。

也许还有另一个库可以做同样的事情。

1 个答案:

答案 0 :(得分:4)

您可以像使用UITableView一样使用Koloda。开始异步获取viewDidLoad中的对象,然后在回调中调用reloadData,因此Koloda必须重新配置其视图。

注意:存储库https://github.com/Yalantis/Koloda/tree/networking_example

中有networking_example