Saturday, December 20, 2008

SimpleBeep

This is based on a tutorial from Youtube
Agenda: Draw a button on a window which beeps when it is pressed
How

1. Create a cocoa application
2. Open MyDocument
3. Add an object. Name it BeepController in the class box and add a method beepTest:
4. Please note that the method name ends in a colon.
5. Drag a button and name it Beep
6. Drag a line from button to controller with the *Ctrl* key pressed
7. Connect the button press with the action handeler beepTest
8. Generate classes from Interface Builder's menu
9. Edit classes to make sure that the generated BeepController class inherits from NSDocument and not NSObject
10. Add beeping code to the controller's beepTest method. NSBeep()
11. Build and go.

Problems
1. NSBeep refuses to beep

Modifications
1. The classes can be created earlier and hooked up later