I am creating a calculator view that uses sliders to set textbox values. Each textbox has a slider that corresponds to it. The code for updating textbox values is as follows:
- (void) updateAlphaTextField:(id)sender
{
int value = [alphaSlider value];
NSString *stringValue = [NSString stringWithFormat:@"%d",value];
[alphaTextField setText:stringValue];
}
However I have about 20 textboxes (and 20 corresponding sliders) that I would like to demonstrate this behavior and I don’t want to write 20 of these update functions.
Is there a function that I can write that could watch all the sliders and update a corresponding textbox with the right value? If so, how do I make my IB connections to get it to work? (The above function required 1 IB connection to be made)
Or even better is there a Cocoa Touch function that would allow me to do this easily?
Put tags in your
UITextFieldsandUISliders. For instance: UITextField 1, would havetag1 and theUISlider1, would also havetag1. Then, create an IBOutlet collection with all yourUITextFields. You can use this to help you out:http://www.bobmccune.com/2011/01/31/using-ios-4s-iboutletcollection/
In your function do this:
}