LoginSignup
1
1

More than 5 years have passed since last update.

XIBやストーリーボードを使わずにEmpty Projectに画面を1つ追加するには

Last updated at Posted at 2013-06-06
  1. [New Project]->
    [Empty Project]

    プロジェクトがつくられ、AppDelegate.hAppDelegate.mができる。

  2. [New File]->
    [UIViewCotroller subclass]->
    [class名]ViewController1
    [with XIB]チェックを外す

    プロジェクト内にViewController1.hViewController1.mができる。

  3. コードを書く

    まず表示させる画面をつくる

ViewController1.m
#import "ViewController1.h"

@implementation ViewController1

〜略〜

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

    UILabel* label = [[[UILabel alloc] initWithFrame:self.view.bounds] autorelease];
    label.text = @"Hello, world!";
    label.textAlignment = UITextAlignmentCenter;
    label.backgroundColor = [UIColor whiteColor];
    label.textColor = [UIColor blackColor];
    label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:label];
}

〜略〜
  1. コードを書く

    次にアプリケーションから先ほど作成した画面を呼び、自身のビューに追加する

AppDelegate.h
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UIViewController* viewController1_;
}

@property (strong, nonatomic) UIWindow *window;

@end
AppDelegate.m

〜略〜

- (void)dealloc
{
    [viewController1_ release];

    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    viewController1_ = [[ViewController1 alloc] init];
    [self.window addSubview:viewController1_.view];
    [self.window makeKeyAndVisible];
    return YES;
}

〜略〜

これで以下のような画面が表示される。

スクリーンショット(2013-06-06 12.38.24).png


ブログやってます:PAPA-tronix !

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1