使用Koloda视图库设置dataSource错误

时间:2016-07-21 08:29:58

标签: ios swift

我正在使用图书馆KolodaView:https://github.com/Yalantis/Koloda

尝试为dataSource

设置StudyViewController方法时出错

以下是代码:

import UIKit
import Koloda

class StudyViewController: UIViewController {

@IBOutlet weak var kolodaView: KolodaView!

override func viewDidLoad() {

    super.viewDidLoad()

    kolodaView.dataSource = self // Error here
    kolodaView.delegate = self

}
}

extension StudyViewController: KolodaViewDelegate {
}

extension StudyViewController: KolodaViewDataSource {

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

func koloda(koloda: KolodaView, viewForCardAtIndex index: UInt) -> UIView {
    return UIImageView(image: UIImage(named: "Image"))
}

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

错误消息为:线程1:EXC_BAD_ACCESS

1 个答案:

答案 0 :(得分:1)

我设法重现你的错误并解决它。

您似乎正在使用故事板但是您没有设置您的Koloda视图的类。这意味着当您尝试设置委托时它将为零。

您需要做的就是将课程设置为" KolodaView"如下图所示: enter image description here