开发者

How to know which slider is selected

开发者 https://www.devze.com 2023-03-06 08:09 出处:网络
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;You can use the Tag propert

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;


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.


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 to NSSliders (for example NSString), their is no default type, just use the following method.

  • -[NSControl setIntValue:]
0

精彩评论

暂无评论...
验证码 换一张
取 消