into Swfit (i) nibname

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.