iOS Application Architecture

Source: Internet
Author: User

MVC Development Model

What is MVC, I believe programmers with some development experience should know.

m--model, providing data for the program

v--view to provide user interface

c--controller, which is used to control the view, i.e. V

In an iOS program, a controller corresponds to a view. The interface that is presented to the user is determined by the controller.

is the standard file for the Singleview program that Xcode creates.

The Viewcontroller in the figure is actually the controller, and Main.storyboard is used to create the view. Because Xcode does not know what data you are providing, it does not help you create the model file, which is generally the responsibility of the developer.

How the view is created (Uiscreen,uiwindow)

As we all know, all the interfaces are drawn. So, how to draw, where to draw is a problem. Don't talk about how to draw first, we talk about where to draw. Borrow an official picture to say

In the diagram, the program draws a text and a button that is actually drawn on the window (which is a UIWindow class).

Since we have to draw something, we have to know the size of the paper (window), and the size of the window is the size of the screen, a UIScreen class represents a screen, so we use the size of the UIScreen class instance to initialize the size of the window. The following code is often seen in some programs for this reason.

Application lifecycle, hypervisor State switching

From the start of the program to being destroyed, there will be a stage where we can do different things at different stages. The Appdelegate document provides us with this. The Appdelegate class complies with the Uiapplicationdelegate protocol. The main task of the Protocol is to respond to different states of the program. The state of the program is mainly:

    • Not running: The program has not been started by the user or the system, or has been terminated
    • Inactive: The program has been transferred to the foreground, but it has not yet received the event, which is usually short-lived.
    • Activation: The program can handle the event at this time, or it can say that it is interacting with the user.
    • Running in the background: the user is not visible, but still has the ability to execute some code.
    • Pending: The program still resides in memory, but cannot execute any code.

It is enough to explain how the state of the program is switched.

Different stages correspond to the method of execution:

Start-up phase:

application:willfinishlaunchingwithoptions:

Application:didfinishlaunchingwithoptions:

Switch to front desk:

applicationdidbecomeactive:

Switch to Background:

Applicationdidenterbackground:

To switch to an inactive state:

applicationwillresignactive: (Executed when the program is left by the foreground state)

Applicationwillenterforeground: (Executes when the program is left in the background state)

Terminate:

applicationwillterminate:

Where the window property should be initialized in front of us, I'm sure we all know it:

Application:willfinishlaunchingwithoptions:

Because we should initialize the corresponding properties before the program is activated, it is appropriate to initialize the Window property in the Appdelegate class.

iOS Application Architecture

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.