Loading UIViewController "from" Nib File

You need to allocate your ViewController, then initialize it by telling the iOS the name of the nib.

I see you're using Swift; I'm afraid I don't know swift, only objective-c. But here is how it would be done in objective-c:

[self.navigationController pushViewController [[[CoolViewController alloc] initWithNibName: @"CoolDesign" bundle: nil] autorelease];

... where "CoolDesign" is the base name of your nib. That is, you create CoolDesign.xib in Interface Builder, Xcode compiles the XML - text - xib into CoolDesign.nib, then you tell initWithNibName to open just @"CoolDesign".

It's not enough just to tell Interface Builder that a design document is a UIViewController. While in principle the iOS could figure out what you mean, also in principle you could have multiple nibs for a single UIViewController subclass.


Try this, you can load a UIViewController with nibName:

Swift

self.navigationController!.pushViewController(CoolViewController(nibName: "CoolViewControllerNibName", bundle: nil), animated: true )

Objective-C

CoolViewController*coolViewCtrlObj=[[CoolViewController alloc] initWithNibName:@"CoolViewControllerNibName" bundle:nil];
[self.navigationController pushViewController:coolViewCtrlObj  animated:YES];