Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question has nothing to do with a picker view. You want to listen for changes to the text field and update the conversion and the label based on the latest text entered into the text field.</p> <ol> <li>Setup a method to be called on the text field when its value changes.</li> <li>All of the code in your picker view delegate method that calculates the conversion and updates the label needs to be put in another method that can be called from two places.</li> <li>In the new method that reacts to changes in the text field, call the method you just created that does the conversion and updates the label. </li> </ol> <p>So at this point your picker view delegate method and your text field change method both call the method that gets the conversion from the picker and the text from the text field, then does the conversion, and finally updates the label.</p> <p>Edit: More details</p> <p>Refactor the current picker view delegate method like this:</p> <pre><code>-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { [self updateConversionLabel]; } - (void)updateConversionLabel { float convertFrom = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0]] floatValue]; float convertTo = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:1]] floatValue]; float input = [inputText.text floatValue]; float to = convertTo; float from = convertFrom; float convertValue = input; float relative = to / from; float result = relative * convertValue; NSString *convertFromName = [_convertFrom objectAtIndex:[pickerView selectedRowInComponent:0]]; NSString *convertToName = [_convertFrom objectAtIndex:[pickerView selectedRowInComponent:1]]; NSString *resultString = [[NSString alloc]initWithFormat: @" %.4f %@ = %.4f %@",convertValue, convertFromName, result, convertToName]; resultLabel.text = resultString; } </code></pre> <p>You then need to create a method to handle the changes to the text field:</p> <pre><code>- (void)textFieldChanged:(UITextField *)textField { [self updateConversionLabel]; } </code></pre> <p>Now in IB, hook up the <code>textFieldChanged:</code> method to the "value changed" event for the <code>inputText</code> text field. I don't use IB so I don't know the exact term for doing that.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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