问题描述
在Apple文档中, UISwitch
的函数 setOn(on:Bool,动画:Bool)
不发送操作.在iOS 10之前,它可以正常工作,但是在iOS 10中调用它后,它将发送操作.在"ValueChanged"事件中调用它以强制切换回去,因此我两次获得了该事件的操作.是iOS 10中的错误吗?
As Apple's document write, UISwitch
's function setOn(on: Bool, animated: Bool)
does not send action. It works fine before iOS 10, but it will send action after I call it in iOS 10. I call it in "ValueChanged" event to force switch back, so I got this event action twice. is it a bug in iOS 10?
推荐答案
DispatchQueue.main.async {
sender.setOn(flag, animated: animated)
}
它在Xcode 8中对我有效.
it works for me in Xcode 8.
但直接在主线程上调用 UISwitch.setOn(_:animated:)
无效.
but call UISwitch.setOn(_:animated:)
directly on main thread doesn't work.
感谢@codiction:
thanks to @codiction:
UISwitch.setOn(_:animated:)
可以在主线程上调用直接,但不能在iOS 10上的UISwitch ValueChanged操作中直接调用.
UISwitch.setOn(_:animated:)
can be called direclty on main thread, but can't be called directly in UISwitch ValueChanged action on iOS 10.
这篇关于UISwitch setOn(:,animated :)不能作为文档使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!