我有一个UISwitch
它执行一个操作。我需要显示带有/无选项的警报。如果用户选择选项否,则不应发生任何情况。交换机的用户界面不应该改变。防止UISwitch改变UI状态
这是我的代码。
func toggleSwitchValueChanged(sender: UISwitch) {
let alert = UIAlertController(title: "", message: "This operation will reset the photos you have renamed already. Proceed?", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "No", style: .Cancel) { action in
return
})
alert.addAction(UIAlertAction(title: "Yes", style: .Default) { action in
self.api.includeCoverPhoto(sender.on)
})
alert.preferredAction = alert.actions[1]
presentViewController(alert, animated: true, completion: nil)
}
我在UISwitch
的值更改事件中触发此方法。
问题是如果我选择否,操作不会继续。但UISwitch
的用户界面已更改为另一个状态。
如何阻止这种情况的发生?
你可以切换到默认状态,这就是我们通常做的。 –
是的,'sender.setOn(!sender.on,animated:true)'确实有效,但我希望事先有办法阻止它,因为它看起来不太好。 – Isuru