UIStepper:如何知道用户单击了步进器的哪个按钮(减号或加号按钮) [英] UIStepper: how to be aware which button (minus or plus button) of the stepper has been clicked by user
本文介绍了UIStepper:如何知道用户单击了步进器的哪个按钮(减号或加号按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么可能知道用户单击了步进器的哪个按钮(减号或加号按钮)?
How do I possibly know which button(minus or plus button) of the stepper has been clicked by user?
- (IBAction)buttonStepper:(id)sender {
int stepperValue = self.outletStepper.value;
self.label.text = [NSString stringWithFormat:@"%d", stepperValue];
}
谢谢:3
推荐答案
您可以代替stepTarget属性来观察steppers值属性,并要求在更改字典中同时接收旧值和新值
You can, instead of addTarget:action, observe the steppers value property and ask to receive both old and new value in the change dictionary
{
UIStepper *stepper = ...;
[stepper addObserver:self forKeyPath:@"value"
options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew
context:0];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == stepper) {
double oldValue = change[NSKeyValueChangeOldKey];
double newValue = change[NSKeyValueChangeNewKey];
double change = newValue - oldValue;
}
}
或子类UIStepper并在覆盖的-setValue中进行计算:
or subclass UIStepper and do the calculation in an overridden -setValue:
这篇关于UIStepper:如何知道用户单击了步进器的哪个按钮(减号或加号按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文