[Xcode] xcode8でストーリーボード使わずxibを使う

いっつも忘れるので記録。

  1. シングルViewアプリケーションでプジェクトを作成
  2. Main.storyborardを削除(MoveToTrash)
  3. Info.plistの Main storyboard file base nameを空にする
  4. FileでView(xib)ファイルをつくる。ViewController.xibとする
  5. ViewController.xibのFile’s OwnerのCustom ClassをViewControllerにする
  6. ViewController.xibのFile’s OwnerのoutletのviewをIB上のviewをつなげる
  7. AppDelegate.hとAppDelegate.mを以下のように変更する

AppDelegate.hに以下のプロパティを加える


#import "ViewController.h"
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UINavigationController *navigationController;

AppDelegate.mに以下を追加


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

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
_navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
_navigationController.navigationBarHidden = true;
[self.window setRootViewController:_navigationController];

[self.window makeKeyAndVisible];
return YES;
}

でビルドでいいとおもう・・・

Posted in iOS