Ios 更新滑块值

Ios 更新滑块值,ios,Ios,我有两个ViewController,ViewController_A和ViewController_B。ViewController_A有一个带doSlider方法的滑块,如下所示 - (void)doSlider:(float)value{ [viewController_B getValue:[slider_1 value]]; } - (void)getValue:(float)value{ width = value; NSLog(@"getValue %f", widt

我有两个ViewController,ViewController_A和ViewController_B。ViewController_A有一个带doSlider方法的滑块,如下所示

- (void)doSlider:(float)value{
  [viewController_B getValue:[slider_1 value]];
}
- (void)getValue:(float)value{
  width = value;
  NSLog(@"getValue %f", width);
}
ViewController_B有一个getValue方法,如下所示

- (void)doSlider:(float)value{
  [viewController_B getValue:[slider_1 value]];
}
- (void)getValue:(float)value{
  width = value;
  NSLog(@"getValue %f", width);
}

当我在ViewController_A中拖动滑块时,ViewController_B将打印出宽度值。但它似乎只在getValue方法中可用。我是否可以将宽度值传递给ViewController_B中的其他方法,例如touchesMoved。谢谢。

是的。使用
[slider\u 1 value]
获得滑块值后,您可以随意使用它。当您将该值传递给
getValue:
并指定给
width
时,您可以随意使用
width

我使用“width”在touchsmoved中设置笔刷大小,但它始终为零。如何将“宽度”传递给touchsmoved?
touchsmoved:withEvent
双精度的数字没有多大关系。这一定是因为您的代码与将参数传递给touchesMoved:withEvent有关。您的意思是不可能将参数传递给touchesMoved吗?不,这当然不是不可能的。但是,参数是
NSSet
NSEvent
——它们与
double无关。因此,至少,您需要以某种方式打包您的
double`。如果我返回getValue的宽度值,是否可以在TouchsMoved中设置笔刷大小?委托或@protocol呢?为什么不把
width
作为viewController_B的一个属性。实际上,在我看来,这就是你正在做的,但也许我遗漏了什么。