More Objective-C Hello World

September 28th, 2009 by Lizabeth Arum Leave a reply »

So, the joke in class was “will there be a HelloWorld27?”

Probably not, but we are up to HelloWorld4.

So the class is small, but made up of students with very different programming backgrounds. Two of the students are very comfortable in the Revolution environment, but are having some difficulty getting used to the C syntax. The other four students have used Java and/or Arduino, and while the syntax is different, they are finding it easier to adapt what they know to what we are doing.

I find for some students pictures are essential.

HelloWorld04

  1. Create a an image of yourself with the following dimensions:
    dimension
  2. Save it as a png on the desktop

  3. Open Xcode and create a new project

  4. Create a View Based application
    view_based

  5. Save it as HelloWorld04

  6. Open up the HelloWorld04ViewController.h file

  7. Create a UILabel pointer named label of type IBOutlet

  8. Below the closed curly brace create an (IBAction) named hello and pass it (id)sender

  9. Open the Implementation file and define the hello function so that the text of label is set to a message

  10. Save the files

  11. CTRL+click on the Resources folder and add the png. Make sure to Copy items into destination group’s folder(if needed)

  12. Open up the main nib file

  13. Double click on the HelloWorld04ViewController in the MainWindow.xib
    viewController
  14. Click on the link
    link
  15. From the library add a UIImageView

  16. In the attribute window set the image to your png

  17. From the library drag a UILabel onto the view. Adjust the size

  18. Clear the Text in the Text field

  19. Choose a color for the text in the attribute window

  20. From the library drag a button on to the view and change the label on the button to Press Me

  21. In the xib window click on File’s Owner and press ⌘+2.

  22. Connect label to the label in the view.

  23. connect hello: to the button and select Touch up inside

  24. Save the xib file

  25. Build and run

  26. Modify the code so that the text keeps toggling between two expressions.
    animation
  27. Add an NSLog() statement to print out the current text to the console.

  28. Save the xib file

  29. Build and run (⌘+⇧+R)

Advertisement

Leave a Reply