3

我添加UISlider以编程方式查看如下:

UISlider * sideslider = [[UISlider alloc] initWithFrame:CGRectMake(canvasWidth +((canvasWidth) - (recwidth) / 4) /b2, recheight - 70, (recwidth) / 4, 20)];
[sideslider setMaximumValue:solution0->Plan->HDivisions.count];
// sideslider 
int slidervalue = sideslider.value;
[self addSubview:sideslider];

我需要添加这个事件处理程序

-(IBAction)updateside:(UISlider *)sender;

创建后到这个滑块?

4

2 回答 2

8
[slider addTarget:self action:@selector(updateside:) forControlEvents:UIControlEventValueChanged];
于 2012-07-13T05:48:16.977 回答
4

您需要分配:

[sideslider addTarget:self action:@selector(updateside:) forControlEvents:UIControlEventValueChanged];

要计算出发送者的值 ( sideslider):

-(IBAction)updateside:(id)sender
{
    UISlider * slider = (UISlider*)sender;
    NSLog(@"Slider Value: %.1f", [slider value]);
}
于 2012-07-13T05:49:11.210 回答