O'Reilly logo

iOS® 8 for Programmers: An App-Driven Approach with Swift™, Third Edition by Abbey Deitel, Harvey M. Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.6.4 Method submitGuess

Figure 5.23 defines the @IBAction submitGuess (created in Section 5.4.6) which is called each time the user touches an enabled segment on one of this app’s UISegmentedControls. Lines 111–112 use UISegmentedControl method titleForSegmentAtIndex to get the title text for the selected segment—this is the user’s guess. Line 113 gets the displayable country name for the correctAnswer, then line 114 increments totalGuesses.

  108      // called when the user makes a guess  109      @IBAction func submitGuess(sender: UISegmentedControl) {  110          // get the title of the bar at that segment, which is the guess  111          let guess = sender.titleForSegmentAtIndex(  112              sender.selectedSegmentIndex)!          ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required