思い立ったが吉日!

iOSが好きです。

Storyboardを使わず、Xibファイルで開発をすすめるとき

Xibファイルによるプロジェクト開発

準備

Storyboardを使わずにXibファイルでプロジェクトを進める際のViewControllerの呼び出し

  • MainStoryBordを削除

f:id:watarotten:20151023185913p:plain

  • TARGETSのGeneralのMain Interfaceのmainstoryboardを削除

f:id:watarotten:20151023185806p:plain

  • AppDelegateを編集
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 以下のコードを追記
    // windowを画面いっぱいに生成
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    
    BRViewController* firstView = [[BRViewController alloc] init];
    self.window.rootViewController = firstView;
    [self.window makeKeyAndVisible];
    
    return YES;
    
}

遷移について(遷移先のViewController)

  • コードから生成し、Xibを読み込むとき
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:@"ViewController名" bundle:nil];
    if (!self) {
        return nil;
    }
    
    return self;
    
}
-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (!self) {
        return nil;
    }
    
    return self;
    
}