使用Koloda库与Parse数据源

3
我正在使用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
    }
}

上述代码可以很好地使用我在资源中存储的六个图像。我想要的是用ParseUser的数据填充每张卡片(文本和图像)。我一直在思考类似于使用ParseData填充tableView的解决方案,但我找不到正确的解决方案。这就是KolodaView的目的:
KolodaView是一个专门设计用于简化iOS上实现类似Tinder的卡片的类。它添加了便利功能,例如UITableView样式的dataSource/delegate接口,用于动态加载视图以及高效的视图加载和卸载。
也许还有其他库可以完成相同的任务。
1个回答

4

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

注意:存储库中有networking_example示例https://github.com/Yalantis/Koloda/tree/networking_example


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接