2011/04/30

Interface Builderを使わない方法

仕事上Interface Builder(以下IB)を使うとソースコードの管理がしにくくなるのとXcode4になってからは統合されたけど3までは別アプリになってたので開発しにくい・・という事でIBは使わない方針でした。けっこうIB使わないやり方って忘れやすいので覚え書き。


まず、ターゲット設定の"Main Interface"を消す




IBのファイル(拡張子が.xib)を削除

AppDelegate.hの修正
#import 
@class SampleViewController;
@interface SampleAppDelegate : NSObject  {
    UIWindow *window;
    UIViewController *viewController;
}
@property (nonatomic, retain) UIWindow *window;
@end

AppDelegate.mの修正
#import "SampleAppDelegate.h"
#import "SampleViewController.h"
@implementation SampleAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    viewController = [[SampleViewController alloc] init];
    window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    return YES;
}
- (void)dealloc
{
    [window release];
    [viewController release];
    [super dealloc];
}
@end

main.mの修正
int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");

で、よし。

IBは楽だし便利だけど、私としてはがしがしコードを書きたいな。
そう思うのはIB全く使ってないからかもしれないけど、、ね。

1 件のコメント:

  1. Thanks on your marvelous posting! I certainly enjoyed reading it, you will be a
    great author. I will be sure to bookmark your blog and will eventually
    come back very soon. I want to encourage you to continue
    your great work, have a nice holiday weekend!

    Feel free to visit my site; hack clash of clans

    返信削除