I have a UISlider that I w开发者_如何学Pythonant to update a UITextField for the value of 1-100 in real time, i.e. I slide the slider and the value updates.
How can I do this? I couldn't find anything in the class reference.
You will need to listen for value changes on the slider. You can set this up in interface builder or in code.
//Add event for valueChanged in viewDidLoad
[self.slider addTarget:self
action:@selector(sliderValueChanged:)
forControlEvents:UIControlEventValueChanged];
...
-(void)sliderValueChanged:(id)sender
{
self.textField.text = [NSString stringWithFormat:@"%d",
(int)(slider.value * 99) + 1];
}
精彩评论