さぁ!ソースいじるぞ!!!
まずは、HelloWorldAppDelegate.hです。
#import <UIKit/UIKit.h> @interface MainView : UIView { UITextView *textView; } @end @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; MainView *myMainView; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end
次にHelloWorldAppDelegate.mです。
#import "HelloWorldAppDelegate.h" @implementation MainView - (id)initWithFrame:(CGRect) rect{ self = [super initWithFrame:rect]; if(self != nil){ textView = [[UITextView alloc] initWithFrame:rect]; textView.text = @"Hello World!"; [self addSubview:textView]; } return self; } -(void)dealloc{ [textView release]; [super dealloc]; } @end @implementation HelloWorldAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { NSLog(@"start"); CGRect screenBounds = [[UIScreen mainScreen] applicationFrame]; CGRect windowBounds = screenBounds; windowBounds.origin.y = 0.0; self.window = [[UIWindow alloc] initWithFrame: screenBounds]; myMainView = [[MainView alloc] initWithFrame:windowBounds]; [window addSubview:myMainView]; // Override point for customization after application launch [window makeKeyAndVisible]; } - (void)dealloc { [myMainView release]; [window release]; [super dealloc]; } @end
これで「ビルドして実行」を選ぶとiPhoneシミュレータが立ち上がり
こんな画面がでれば成功ですね!
できたできた!ということで
iPhoneアプリでInterface Builder使わずに開発する際のチュートリアルにでもなれば幸いです。