简体   繁体   English

如何通过用户交互或IOS中的代码来确定切换视图值是否已更改?

[英]How can I decide if switch view value was changed by user interaction or by code in IOS?

I have a switch view on my UI and I'd like to handle the event when its value is changed. 我的UI上有一个切换视图,我想在其值发生变化时处理该事件。 To perform this I've made an IBAction method to handle value changed event. 为了执行此操作,我已经制作了一个IBAction方法来处理值更改事件。 So far so good. 到现在为止还挺好。

My problem is I can't decide if change was performed by - code (it may happen in my app) - user interaction 我的问题是我无法决定是否通过 - 代码(可能在我的应用程序中发生)进行更改 - 用户交互

How can I decide if it was changed by a user interaction or by code? 如何通过用户交互或代码来确定它是否已更改?

Is there a specific method that changes the switch value when it's done by code only? 是否有一种特定的方法可以在仅通过代码完成时更改开关值? If so, maybe you could use that method to set a boolean/flag to check against when you need to decide/handle the event. 如果是这样,也许您可​​以使用该方法设置布尔/标志,以便在需要决定/处理事件时进行检查。

In Apple ScrollView / ScrollPages Example they have a simmilar situation: 在Apple ScrollView / ScrollPages示例中,他们有一个类似的情况:
They have to decide whether an event was self(=code) triggered, or by the user. 他们必须决定事件是自我(=代码)触发,还是由用户决定。
They simply set a variable (before programatically calling) to distinguish between this two situations. 他们只是设置一个变量(在编程调用之前)来区分这两种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM