まずは本買いました!

いろいろ、調べてみると、まずはこんな結果に。
・画面作成にInterface Builderは使わないほうがいい
・その方が後々、カスタマイズしやすい
なるほど。。。
これ前提で探した本がこれ。
全てInterface Builder使わずに画面作成する方法が(英語やけど)書いてあります

iPhone SDK Application Development: Building Applications for the AppStore

iPhone SDK Application Development: Building Applications for the AppStore

ちなみに新宿のコクーンタワーのブックファーストで売ってます!

プロジェクト作成!

XCodeはインストール済。iPhone SDKもダウンロード済です。
なので、早速XCodeを起動して、プロジェクトを作成します。

XCode上で「ファイル」→「新規プロジェクト」を選択します
すると、こんな画面がでてくるので、「Window-Based Application」を選択します。

プロジェクト名は「HelloWorld」として完了します。

Interface Buiderとの関係を断ち切る!

初めにInterface Builderとの関係を断ち切ります。
ResourcesフォルダにあるMainWindow.xibファイルを削除します。

次に、同じResourcesフォルダにあるInfo.plistファイルを開き
最終行の[Main nib file base name]の行を削除します。

最後にOther Sourcesフォルダにあるmain.mファイルを開きます。
UIApplicationMainメソッドを呼び出している行を、下記のように書き換えます。

int retVal = UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");

さぁ!ソースいじるぞ!!!

まずは、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使わずに開発する際のチュートリアルにでもなれば幸いです。