ラベル notIB の投稿を表示しています。 すべての投稿を表示
ラベル notIB の投稿を表示しています。 すべての投稿を表示

2010年8月31日火曜日

IBを使わない場合のviewとviewControllerの作成

View-basedApricationテンプレートを使用する場合、viewとviewControllerを自作する必要がある。

1.
(プロジェクト名)AppDelegate.mファイルの、application:didFinishLaunchingWithOptionsメソッドで、UIWindowとUIViewController(を継承したRootViewController)を作成してUIWindowに追加する。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

RootViewController *viewController = [[RootViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];

[window addSubview:navigationController.view];
[window makeKeyAndVisible];

return YES;
}

2.
UIViewCOntrollerクラスのloadViewをオーバーライドして、self.viewにviewを追加する。

-(void)loadView{
CGRect bounds = [[UIScreen mainScreen] applicationFrame]; 
UIView *contentView = [[UIView alloc] initWithFrame:bounds];

contentView.backgroundColor = [UIColor redColor];
self.view = contentView;

[contentView release];
}

参考PDF:iPhone OS View Controller プログラミングガイド プログラムによるビューの作成

2010年8月17日火曜日

InterfaceBuilder(IB)を使わないための準備

Xcodeで、IBを使わないためには以下の処理を事前に行う。
------------------------------

Window-based Applicationテンプレートを選択する。

*.xibファイルを削除する(一緒にゴミ箱に入れる)。

main.mの14行目を以下のように変更する。
int retVal = UIApplicationMain(argc, argv, nil, nil);

最後の引数を「nil」から「AppDelegateクラス名」に変更する。
int retVal = UIApplicationMain(argc, argv, nil, @"bonefire_3_xAppDelegate");

bonefire_3_x-Info.plistファイルのMain nib file base nameを削除する。