O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

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

Adding Keyboard Input to DieView

Open the Dice project from Chapter 18. Although it would be cheating, users would like to be able to set the number on the face of the die by typing a number from one to six.

Accept first responder

Your first task in adding keyboard support is to accept first responder. Add the following property and methods to DieView:

/​/​ ​M​A​R​K​:​ ​-​ ​F​i​r​s​t​ ​R​e​s​p​o​n​d​e​ro​v​e​r​r​i​d​e​ ​v​a​r​ ​a​c​c​e​p​t​s​F​i​r​s​t​R​e​s​p​o​n​d​e​r​:​ ​B​o​o​l​ ​{​ ​r​e​t​u​r​n​ ​t​r​u​e​ ​ ​}o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​b​e​c​o​m​e​F​i​r​s​t​R​e​s​p​o​n​d​e​r​(​)​ ​-​>​ ​B​o​o​l​ ​{​
 ​ ​ ​ ​r​e​t​u​r​n​ ​t​r​u​e}o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​r​e​s​i​g​n​F​i​r​s​t​R​e​s​p​o​n​d​e​r​(​)​ ​-​>​ ​B​o​o​l​ ...

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