Swift has been out for a long time, and has not used it in the project, and now begins to write the project in the swift language, and has encountered problems loading xib when writing the project.
When using objective C, calling Viewcontroller's default constructor is automatically associated to a xib file with the same viewcontroller name, which facilitates the developer and reduces the amount of code. However, in Swift, a new Viewcontroller instance, not the default associated xib, must be specified by the developer to specify the Xib name. This is very unaccustomed to me.
First look at the notation in OC:
ViewController1 *VC1 = [[ViewController1 alloc] init]; This will ViewController1 the default association to VIEWCONTROLLER1.XIB on
//Equals call method
ViewController1 *vc1 = [[ViewController1 alloc] initwithnibname:@ "ViewController1" bundle:nil];
the wording in Swift
var VC = ViewController1 ()//Do not associate Viewcontroller1.xib file
//must specify Xib file, the correct wording is as follows:
var VC = ViewController1 (nibname : "ViewController1", Bundle:nil)
How to let ViewController1 () to find the same name of the Xib file, in fact, originally very simple, rewrite the Init method on the line. In order to prevent each VC to be important to rewrite the Init method, just put the method of rewriting the init into a parent class, the other classes inherit under it.
This is the problem I encountered when I started Swfit project, and I hope I can help you.