Apple just announced general availability for iOS4 so I thought I would document how to write a simple HelloWorld application for the iPhone 4. |
How-To: Write Hello World using Interface Build and Xcode Templates for Apple’s iOS4
- Start Xcode 3.2.3 (available for download as part of the iPhone 4 SDK http://developer.apple.com/iphone/index.action)
- Select View-based Application
- Open View Controller .xib in Interface Builder (located in Resource folder)
- View controllers don’t have a visual presentation
- Mange views, but do *not* display anything of their ow
- Each View Controller has an instance variable called “view” which is set to some type of UIView.
- File’s Owner
- Proxy that represents the object that loaded (and consequently) owns the .xib
- View
- Drag a Label from the Library to the design surface
- Drag a Button from the Library to the design surface
- Close Interface Builder and switch back to Interface Builder
- Open the header file
- Add an instance variable to your class (called an interface in Objective-C)
- Define the property using the instance variable as a backing field
- Switch to the implementation file for the View Controller
- The @synthesize directive automatically generates the setters and getters for us, so all we have to implement for this class is the dealloc method.
- Accessors will only be generated if they don't already exist, so feel free to specify @synthesize for a property, then implement your custom getter or setter if you want. The compiler will fill in whichever method is missing
- Release the UILabel in the dealloc method.
- Switch back to Interface Builder
- Switch to the Inspector Tool Window
- Click on File’s Owner
- Drag the myLabel Outlet to the View UILabel.
- Close Interface Builder and switch back to Xcode
- Add a new Action in the Controller’s header
- Switch back to Interface Builder
- Control Click on the Button and drag Touch Up Inside event to the myButtonPushed Action in File’s Owner
- Implement a UISlider
- Run the application in the Simulator
Once you have the app working in the Simulator, you can deploy to your device.