Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios KolodaView委托方法不工作_Ios_Swift_Swipe - Fatal编程技术网

Ios KolodaView委托方法不工作

Ios KolodaView委托方法不工作,ios,swift,swipe,Ios,Swift,Swipe,我正在使用KolodaView库创建类似Tinder的滑动视图: 我在我的ViewController中实现了delegate方法,如下所示: class ViewController: UIViewController { @IBOutlet weak var kolodaView: KolodaView! override func viewDidLoad() { super.viewDidLoad() kolodaView.dataSource = s

我正在使用KolodaView库创建类似Tinder的滑动视图:

我在我的
ViewController
中实现了
delegate
方法,如下所示:

class ViewController: UIViewController {

    @IBOutlet weak var kolodaView: KolodaView!

    override func viewDidLoad() {
    super.viewDidLoad()

    kolodaView.dataSource = self
    kolodaView.delegate = self

}

extension ViewController: KolodaViewDelegate {

func koloda(koloda: KolodaView, didSwipeCardAtIndex index: UInt, inDirection direction: SwipeResultDirection) {

    if direction == .Right {
        print("apple")
    } else if direction == .Left {
        print("cherry")
    }
}
}

当我刷卡时,它应该打印
apple
cherry
,但当我运行它时,它什么也不做

天哪,你不知道,这是我做过的最经典/最愚蠢的错误

事实上,原始代码是有效的,只是没有在Xcode中打印,因为->

我不小心关掉了控制台

在我尝试了所有善良的人提供的所有方法后,我终于意识到我的调试区域看起来是空的,如下所示:

class ViewController: UIViewController {

    @IBOutlet weak var kolodaView: KolodaView!

    override func viewDidLoad() {
    super.viewDidLoad()

    kolodaView.dataSource = self
    kolodaView.delegate = self

}

extension ViewController: KolodaViewDelegate {

func koloda(koloda: KolodaView, didSwipeCardAtIndex index: UInt, inDirection direction: SwipeResultDirection) {

    if direction == .Right {
        print("apple")
    } else if direction == .Left {
        print("cherry")
    }
}
}

然后我单击了查看->调试区域->激活控制台


然后我终于看到了打印:D

您是否设置了
kolodaView.delegate=self
?@iSashok我设置了,并且我的数据源方法工作正常。所以尝试调试组件,在这个类的第344行和第345行添加断点。他们打电话了吗?@iSashok是的,他们打电话了检查你的
kolodaView
应该不是零