title: How can I use the selectedIndex of a segmentedControl to get the corresponding index of array
body: <p>My code:</p>
  
  <pre><code>class HomeViewController: UITableViewController {
      var segmentedControl: HMSegmentedControl!
      var text = [
          // 名词
          ["音读名词","训读名词","音读与训读的分辨方法"],
          // 形容词
          ["如何分辨形容词", "常用形容词", "形容词的变形规则"]
      ]
  
      override func viewDidLoad() {
          super.viewDidLoad()
          configForSegmentedControl()
      }
  
      func configForSegmentedControl() {
          segmentedControl = HMSegmentedControl(sectionTitles: ["名词","形容词","形容动词","片假名单词","动词","复合动词"])
          segmentedControl.frame = CGRectMake(0, 0, self.view.bounds.width, 44)
          segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10)
          segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe
          segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown
          segmentedControl.addTarget(self, action: #selector(HomeViewController.segmentedControlChangedValue(_:)), forControlEvents: UIControlEvents.ValueChanged)
          if let font = UIFont(name: "BigYoungMediumGB2.0", size: 15) {
              segmentedControl.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: font]
          }
          segmentedControl.backgroundColor = UIColor.whiteColor()
          segmentedControl.selectionIndicatorHeight = 3
          segmentedControl.selectionIndicatorColor = UIColor.blackColor()
  
          tableView.tableHeaderView = segmentedControl
      }
  
      func segmentedControlChangedValue(segmentedControl: HMSegmentedControl) {
          print("Selected index \(segmentedControl.selectedSegmentIndex) (via UIControlEventValueChanged)")
      }
  }
  
  extension HomeViewController {
      override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return text[segmentedControl.selectedSegmentIndex].count
      }
  
      override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          print("cellForRowAtIndexPath:\(segmentedControl.selectedSegmentIndex)")
          let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
          cell.textLabel?.text = text[segmentedControl.selectedSegmentIndex][indexPath.row]
          return cell
      }
  }
  </code></pre>
  
  <p>And here is the console output:</p>
  
  <blockquote>
    <p>cellForRowAtIndexPath:0<br>
    cellForRowAtIndexPath:0<br>
    cellForRowAtIndexPath:0<br>
    Selected index 1 (via UIControlEventValueChanged)<br>
    Selected index 0 (via UIControlEventValueChanged)</p>
  </blockquote>
  
  <p>The <code>cellForRowAtIndexPath</code> gets called before the <code>segmentedControlChangedValue</code> which is why I can't get the correct index to get the element of text array. So what should I do? </p>