几个月前我刚刚开始使用Swift编程,所以为了帮助我学习,我正在使用Tinder
开展类似于Koloda View
的项目。我正在使用Firebase作为我的后端。我下面包含的代码可以很好地处理6张卡片资产,但我正在尝试找出为每个用户创建卡片的方法,并使用这些自定义卡片作为KolodaView
的数据源。
我创建了一个XIB
文件作为这些卡的模板,但我不知道如何从我的数据库中的每个用户获取信息以显示在这些卡上。另外,如何实例化每个用户使用的XIB
文件的多个副本?
对于这个问题的令人困惑的措辞感到抱歉,因为我只是一个初学者,我在努力表达我的问题时遇到了麻烦。请问我是否需要澄清我想说的话。
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
}
}