Note that there are some explanatory texts on larger screens.

plurals
  1. POUISlider in UIToolbar -> can't get slider.value and process it. iOS SDK
    primarykey
    data
    text
    <p>I'm trying to get a UISlider into my UIToolbar and to take the value from it and process it. I also want to be able to change the slider.value via other methods. So, I set it up for the UISlider by it's self (not on a UIToolBar) and everything worked fine. Then, when I put it into the UIToolBar, the value stopped getting sent to and from it (I am NSLogging it whenever it changes and I keep getting 0 returned to me). Here's the relevant section of my code - does anybody have any ideas?</p> <pre><code>- (void)setupToolBarAndSlider { CGRect frame = CGRectMake(0.0, 0.0, 200.0, 30.0); UISlider *slider = [[UISlider alloc] initWithFrame:frame]; [slider addTarget:self action:@selector(sliderValueChanged) forControlEvents:UIControlEventValueChanged]; [slider setBackgroundColor:[UIColor clearColor]]; slider.minimumValue = 0; slider.maximumValue = 8; slider.continuous = YES; slider.value = questionNumberForArray; //Change slider for UIToolbar UIBarButtonItem *skipQuestionSlider = [[UIBarButtonItem alloc] initWithCustomView:slider]; // Set the width of aSlider [skipQuestionSlider setWidth:400.0]; //Set up UIToolBar with Slider in it. UIToolbar *toolBar; CGRect rect2 = CGRectMake(0, toolBar.frame.origin.y , self.view.frame.size.width , 44); toolBar = [[UIToolbar alloc]initWithFrame:rect2]; toolBar.barStyle = UIBarStyleBlackTranslucent; [toolBar setItems:[NSArray arrayWithObjects:skipQuestionSlider, nil]]; [self.view addSubview:toolBar]; } - (void)sliderValueChanged { NSInteger roundedSliderNumber = round(skipQuestionSlider.value); NSLog(@"Slider Value = %d", roundedSliderNumber); } </code></pre> <p>Sam</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload