用swipe改变开关索引
问题描述:
我想知道是否可以用swipe改变开关索引?我正在使用gontovnik的DGRunkeeperSwitch
库。实施后,它看起来像这样:用swipe改变开关索引
它使用的观点为它工作。我试图以编程方式更改它的索引后刷卡。我试了一下这样的,它包含了我的swipeGesture
代码和行应改变index
:
let leftSwipe = UISwipeGestureRecognizer(target: self, action: "respond:")
leftSwipe.direction = .Left
view.addGestureRecognizer(leftSwipe)
let rightSwipe = UISwipeGestureRecognizer(target: self, action: "respond:")
leftSwipe.direction = .Right
view.addGestureRecognizer(rightSwipe)
func respond(sender: DGRunkeeperSwitch!, gesture: UIGestureRecognizer){
if let swipeGesture = gesture as? UISwipeGestureRecognizer{
switch swipeGesture.direction{
case UISwipeGestureRecognizerDirection.Left:
sender.selectedIndex == 0
case UISwipeGestureRecognizerDirection.Right:
sender.selectedIndex == 1
default:
break
}
}
}
但它给我的信号SGABRT错误
“无法识别的选择发送到实例0x7fd788536ad0”
我也尝试刷卡更改默认UISwitch
的值,其工作是这样的:
mySwitch.on == true
我做错了什么,你们能给我正确的方向吗?我认为我在强迫一些东西,但我不知道是什么。
答
respond:
不是具有2个参数的函数的正确签名。
您应该使用#selector(...)
定义操作,大概就像#selector(YourClass.respond(_:gesture:))
+0
它将我引向exc_bad_access错误。这是否意味着它试图将消息发送到无法执行该消息的内存块,或者对象未初始化? –
它扔哪条线路上 – Shubhank
错误不知道是因为它引导我的appDelegate。 –
在你的代码中添加一个异常断点 – Shubhank