Is there a way to track the index selections of a UISegmentedControl?
<p>I have a <code>UISegementedControl</code> with some numbers. When user clicks on a number, it makes that many <code>UITextFields</code> pop out. </p>

<p>I have this running with a switch statement and cases for each number but I wanted to clean up the code, remove the switch statement, and make a loop that checks the number chosen in the segmented control, loops through an array of text fields and makes that many text fields pop out. </p>

<p>It works fine when user selects a number and continues to select higher numbers. </p>

<p>However, if user chooses a number lower than the previous selection, it does nothing (does not hide the undesired text fields). </p>

<p>Is there a way to keep track of the selection made in the segmented control so that I can make some logic statements that check whether new number chosen is > or &lt; lower than previous?</p>

<pre><code>var chosenNumber = segmentedControl.selectedSegmentIndex
var textArray : UITextField = [item1,item2,item3,item4,item5,item6,item7,item8]

            for text in textArray[0...chosenNumber] {
            text.hidden = false
            }

          //logic here to check if newNumber is &lt; than chosenNumber
              for text in textArray[newNumber..&lt;8] {
                text.hidden = true
</code></pre>