March 2008
Intermediate to advanced
288 pages
6h 21m
English
Before we even get to "Hello, World!", we need an even more useless application, "Hello, Window!". This application does nothing more than to create a window and view pair. In fact, because the base UIView class is just a container class, it can't even display any text for you. All you'll see is a black screen. What this application does do is serve as the first few lines of code any GUI application on the iPhone will use.
This application, shown in Example 3-1 and Example 3-2, can be compiled from the tool chain using the following command line:
$ arm-apple-darwin-gcc -o MyExample MyExample.m -lobjc \
-framework CoreFoundation -framework Foundation -framework UIKit
Example 3-1. Example window and view (MyExample.h)
#import <CoreFoundation/CoreFoundation.h>
#import <UIKit/UIKit.h>
@interface MyApp : UIApplication
{
UIWindow *window;
UIView *mainView;
}
- (void)applicationDidFinishLaunching:
(NSNotification *)aNotification;
@end
Example 3-2. Example window and view (MyExample.m)
#import "MyExample.h" int main(int argc, char **argv) { NSAutoreleasePool *autoreleasePool = [ [ NSAutoreleasePool alloc ] init ]; int returnCode = UIApplicationMain(argc, argv, [ MyApp class ]); [ autoreleasePool release ]; return returnCode; } @implementation MyApp - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { window = [ [ UIWindow alloc ] initWithContentRect: [ UIHardware fullScreenApplicationContentRect ] ]; CGRect windowRect = [ UIHardware fullScreenApplicationContentRect ...Read now
Unlock full access