wiedii's memo

色々メモリます。

Xcode5でデフォルトで生成されるStoryBoardって、デフォルトで消せないの?

Single View Applicationを作成するときに、「Use StoryBoard」のようなチェックボックスがあるのかと思ったら、見当たらないですね:(
なので勝手にStoryBoardが作られてしまいます:(
今のところ消し方分かりません:(

代替え案として
1.Empty Applicationを作成する。
2.Single View Applicationを作成した後StoryBoardを削除し、適当なViewControllerを表示させる。
を採用しています。

詳細! Objective-C iPhoneアプリ開発 入門ノート Xcode5+iOS 7対応

詳細! Objective-C iPhoneアプリ開発 入門ノート Xcode5+iOS 7対応

1.Empty Applicationを作成する。
これはそのままですね。
プロジェクト生成後はUIViewControllerのサブクラスを適当に作成して、AppDelegate.m内でインスタンスを生成してあげてそれを表示するという流れになると思います。

2.Single View Applicationを作成した後StoryBoardを削除する。
ここではとりあえず"SingleViewTest"というプロジェクト名を使っています。
プロジェクトを新規作成しSingle View Applicationのテンプレートを選択したら、多分以下の様なファイル構成になっていると思います。
f:id:wiedii:20131031190250p:plain
"Main.storyboard"を削除します(いつもMove to Trashにしてます)。
Supporting Filesディレクトリ内にSingleViewTest-Info.plistがあるので、"Main storyboard file base name"という項目を削除します(丸いマイナスボタンをクリック)。
ここでひとまずビルドしてみます。
多分成功します。
多分…。

あとは以下のようにソースコードを修正してやれば…
AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
    
    return YES;
}
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(id)init{
    if(self = [super init]){
        self.view.backgroundColor = [UIColor orangeColor];
        CGRect button_rect = CGRectMake(0, 0, 100, 50);
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setBounds:button_rect];
        [button setTitle:@"alert" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(showAlert) forControlEvents:UIControlEventTouchUpInside];
        [button setCenter:CGPointMake(self.view.center.x, 100)];
        [self.view addSubview:button];
    }
    return self;
}

-(void)showAlert{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OBJC"
                                                    message:@"Hello, World!"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}
@end


f:id:wiedii:20131031185717p:plain
できましたね:)



詳解 Objective-C 2.0 第3版

詳解 Objective-C 2.0 第3版