Notes for using loadView in iOS Dev (43)

Source: Internet
Author: User

Notes for using loadView in iOS Dev (43)

  •  
  • Never take the initiative to call the loadView Method

    ViewController calls loadView when the view attribute is requested and the current view is nil.

    If you use xib to create a view and initialize ViewController, it means you need to use the initWithNibName: bundle: method. Do not overwrite the loadView method.

    If you create a view manually, overwrite the method.

    Never use [super loadView] When overwriting the loadView Method

    The loadView method is to check whether you have wood or xib, and then use xib to load the basic information. If you have wood or xib, a blank UIView is created and used as the view of the ViewController.

    So when you override this function, you can implement it in this way. It makes no sense that you do not create a blank UIView. When creating a UIView you want, you must note that this UIView instance must be exclusive to this ViewController (not shared by other instances). Otherwise, problems may occur.

    Instantiate the view in loadView and customize the view in viewDidLoad.

    You only need to create a view during loadView and do not customize it.

    When the memory is insufficient, the program will call viewDidUnload to release the memory. This method is opposite to viewDidLoad. When the ViewController is used and the program memory is not so tight, viewDidLoad is called again.

    The operations in viewDidLoad and viewDidUnload are relative.

    When to execute loadView and viewDidLoad

    Generally, the two methods are executed when the ViewController is set to visible. I will explain it further and introduce it later.

    Reference

    Http://my.oschina.net/amoyai/blog/90261

    Reprinted please indicate the blog from laruence: http://prevention.iteye.com

Related Article

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.