March 2008
Intermediate to advanced
288 pages
6h 21m
English
Now that you know how to derive a UIView class, you've got everything you need to write an application that does something—albeit a mostly useless something. In the tradition of our ancestors, we now present the official useless "Hello, World!" application.
This application, shown in Example 3-3 and Example 3-4, can be built using the same command-line arguments as the previous example:
$ arm-apple-darwin-gcc -o MyExample MyExample.m -lobjc \
-framework CoreFoundation -framework Foundation -framework UIKit
Example 3-3. "Hello World!" example (MyExample.h)
#import <CoreFoundation/CoreFoundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UITextView.h>
@interface MainView : UIView
{
UITextView *textView;
}
- (id)initWithFrame:(CGRect)frame;
- (void)dealloc;
@end
@interface MyApp : UIApplication
{
UIWindow *window;
MainView *mainView;
}
- (void)applicationDidFinishLaunching:
(NSNotification *)aNotification;
@end
Example 3-4. "Hello World!" example (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 rect = [ UIHardware fullScreenApplicationContentRect ...Read now
Unlock full access