iOS Learning View Controller

Source: Internet
Author: User

One, custom view (Label-textfield combined view)1. Custom view: A new view that is assembled by itself, outside of the system standard UI. 2, the advantage: iOS provides a lot of UI components, with which we can achieve different functions. However, in actual development, we also need to customize the view. Accumulate your own code base for easy development.    Their own encapsulated view, like the UI space, for other projects, can greatly reduce development costs and improve development efficiency. 3, high-quality code features : Reusable, portable, refining and so on.     ( cohesion Poly, low coupling ). 4. Custom View Steps
    • Depending on the requirements, the classes inherited by the custom view are different. A general custom view is inherited from the UIView.
    • Create a UIView subclass: @interface Ltview:uiview
    • To add a child view in the initialization method of a class

  • The. h file of the class provides some interface (methods) to facilitate the operation of the child view
  • @property(Nonatomic,Strong)UILabel*leftlabel;//LeftLabel
    @property (nonatomicstrong) uitextfield *rightfield; // right text box
5. Summary
    • The custom Ltview (Uilabel,uitextfield) uses a design pattern: composite design mode .
    • Composite design pattern: A class that uses Class B (or more classes) as its own member (instance variable).
    • Compositing in iOS is a particularly common design pattern. iOS new controls are often combined with existing controls.
Second, view Controller1, the view controller is an important bridge between the application data and the view, each iOS application displays only one user interface, the content is displayed by the controller or a group of view Controller coordinated management. Therefore, the view Controller provides a basic framework to build the application. 2. Uiviewcontroller is the parent class for all view controllers. 3. iOS provides a number of built-in view controllers to support standard user interface sections such as navigation Controllers (Uinavigationcontroller), tag controllers (Uitabbarcontroller), Table View Controller (Uitableviewcontroller) and so on. 4. Function
    • Controls the change in view size, layout view, Response time.
    • Detects and handles memory warnings.
    • Detects and handles screen rotation.
    • Detects the switch of the view.
    • Realize the module independence, improve the reusability.
Third, the view controller specifies the view1. How to set up
    • The custom view class inherits UIView. Adds a child view control in the initialization method.
    • Override the controller's Loadview method. Creates a custom view object and designates it as the controller's view. (Note: The Loadview method is called when the controller's view is nil and is used when creating the view in the form of a change.) Loadview is the method that is called when the view is first loaded by using code to generate the view, and is used to implement the control using (write) code. )
    • Set the child view Control object to the properties of the custom view class, set in the Viewdidload method: Add action, set delegate, and so on.
    • Add button click event Implementation and proxy method implementation in controller.
2. View Controller life cycle
Iv. MVC1. MVC Overview
    • Uiviewcontroller is the core of the MVC design pattern.
    • MVC is a framework-level design pattern.
    • M is model, which is used primarily to establish a data model (i.e. the structure of the data).
    • V is view, the main function is to display the data.
    • C is the controller, mainly the communication of the control M and V
2. Five, screen rotation1, the view controller itself can detect the rotation of the screen, if you want to handle screen rotation, you need to rewrite several methods
    • supportedinterfaceorientations(sets the orientation of the device to support rotation, and if not added, the view controller will not be able to detect the rotation of the screen).
    • willrotatetointerfaceorientation:duration:(Pause music, turn off view interaction, etc.).
    • willanimaterotationtointerfaceorientataion:duration:(add custom animations, etc.).
    • didrotatefrominterfaceorientataion:(play music, open view interaction, and so on).
2. Processing of views
    • Note that the view controller automatically adjusts the view size to fit the screen rotation, and bounds is modified to trigger the view's Layoutsubviews method.
    • View overrides the Layoutsubviews method, which is re-layout according to the device orientation.
    • [UIApplication shareapplication].statusbarorientation provides the current orientation of the device.
VI. Memory Warning1. Memory warning Source: If the phone memory is 80M, the program will send a memory warning message for each view controller when the memory is close to 80M when the program is running. 2. How to deal with
      • The controller detects memory warnings so that we can avoid crash caused by insufficient memory.
      • Override the Didreceivememorywarning method in the defined controller subclass.
      • Frees resources that are temporarily inapplicable (Self.view and view sub-views such as data objects, images).

iOS Learning View Controller

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.