2012-07-13 65 views
3

我添加UISlider查看程序是這樣的:到UISlider分配方法以編程方式使用Objective-C的

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; 

添加到這個滑蓋的?

+0

顯然,是的,你確實需要。 – 2012-07-13 05:48:32

回答

8
[slider addTarget:self action:@selector(updateside:) forControlEvents:UIControlEventValueChanged]; 
+0

你打敗了我! – WrightsCS 2012-07-13 05:50:19

+2

@WrightsCS無可能,無論如何,你從我那裏得到+1;) – 2012-07-13 05:51:13

+0

;-D ............ – WrightsCS 2012-07-13 05:51:53

4

您需要分配:

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

找出發送者(sideslider)值:

-(IBAction)updateside:(id)sender 
{ 
    UISlider * slider = (UISlider*)sender; 
    NSLog(@"Slider Value: %.1f", [slider value]); 
} 
相關問題