如何知道选择了哪个滑块
我的应用程序中有多个滑块,如何知道选择了哪个滑块。以及如何将滑块值设置为整数类型,其中 double 是默认类型;
I have multiple sliders in my application,how to know which slider is selected. And how to set the slider values to integer type where double is default type;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用滑块的 Tag 属性来分配一个整数(或者更好的是,使用枚举)。如果您有多个具有相同目标的按钮或控件,这非常有用。
发送者将是触发操作的控件,您可以从中获取标签。如果需要访问其他属性,还可以转换回原始控件类型。
有关发送方的信息,请参阅 Objective C IBOutlets。
另请注意,通常您会在 Interface Builder (IB) 中设置标签,但也可以在代码中设置它们。
You can use the Tag property of the slider to assign an integer (or even better, use an enum). This is useful if you have multiple buttons or controls with the same target.
The sender will be the control that triggered the action, and you can get the tag from that. You can also cast back to the original control type if you need to access other properties.
See Objective C IBOutlets for information on the sender.
Also note that normally you would set the tag in Interface Builder (IB), but you can also set them in code.
您应该将滑块设置为在方法更改时定位该方法,这样您就可以在滑块更改时收到通知。您应该在界面生成器中执行此操作,但如果由于某种原因您不能,也许您必须动态确定所需的滑块,然后您可以使用诸如
[NSControl setAction:]
[NSControl setTarget :]
NSControl
可以使用各种数据类型(int、float、double)设置其值,甚至某些不适用于NSSliders
的类型(例如NSString
),它们没有默认类型,只需使用以下方法即可。-[NSControl setIntValue:]
You should set up the slider to target a method when it changes, that way you can be informed when a slider changes. You should do this in interface builder but if for some reason you can't, perhaps you have to dynamically determine the sliders needed then you can use methods like
[NSControl setAction:]
[NSControl setTarget:]
NSControl
can have their value set with various data types (int, float, double) even some types that are not applicable toNSSliders
(for exampleNSString
), their is no default type, just use the following method.-[NSControl setIntValue:]