The first IOS program in IOS

Source: Internet
Author: User

I have been doing J2EE development before, but I have not been familiar with objective-C for the first time. I think it is very strange about its syntax. After a week of study, I finally learned the objective-C syntax and started iOS development, watch the basic OC video of Chuanzhi, write the demo and analyze the principle of the IOS program running, and take the following notes:

1. Each application has its own interface, uiwindow inherited from uiview.
Uiview: view, all visible and tangible on the screen is a uiview
2. Problems with uiview:
(A) switching between uiviews
(B) Manage the lifecycle of a uiview
(C) assemble data sources for uiview
 
The above three points are completed by the Controller (uiviewcontroller ).

Uiviewcontroller: by default, a uiview is provided internally to manage the life cycle,
Assemble data to uiview to display and process uiview events

IOS adopts the MVC design mode.

Operating principle:
1. First, execute the main function.
2. Run the uiapplicationmain function.
3. Inside the uiapplicationmain Function
Uiapplicationmain: The third parameter specifies the application Class Name (or subclass). If it is nil, the default value is uiapplication. The fourth parameter specifies the proxy class name.
1> Create a uiapplication instance. This uiapplication is a singleton. An IOS program corresponds to a uiapplication object.
2> the uiapplication object is a symbol of the application.
3> enable a message loop (main loop): used to listen to events on the mobile phone
4> Create another delegate object for uiapplication to monitor the lifecycle of uiapplication.

5> when the life cycle of the uiapplication changes, different messages are sent to the delegate.
* When you run the program for the first time:
Didfinishlaunchingwitexceptions (loaded)->
Applicationdidbecomeactive (get focus)->
* When you click the Home key:
Applicationwillresignactive (out of focus)->
Applicationdidenterbackground (entering the background)
* When you click the application icon again
Applicationwillenterforeground (entering the foreground)->
Applicationdidbecomeactive (get Focus)

Create an iOS Project
# Import "gpbappdelegate. H"
# Import "gpbviewcontroller. H"
@ Implementation gpbappdelegate

-(Void) dealloc
{
[_ Window release];
[_ Viewcontroller release];
[Super dealloc];
}
# Call after The Pragma mark application is loaded
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
Nslog (@ "didfinishlaunchingwithoptions-> Load completed ");
// Initialize a window
Self. Window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease];
// Override point for customization after application launch.
// Input the XIB file name to initialize the yige Controller
Self. viewcontroller = [[[gpbviewcontroller alloc] initwithnibname: @ "gpbviewcontroller" Bundle: Nil] autorelease];
// Set the root controller of the window
Self. Window. rootviewcontroller = self. viewcontroller;


// The window is not displayed by default. You need to call the display method.
// Keywindow is the main window. Only the main window can interact with users.
[Self. Window makekeyandvisible];
// Self. Window. Hidden = no;
Return yes;
}

# Call When The Pragma mark program loses focus (no interaction with users)
-(Void) applicationwillresignactive :( uiapplication *) Application
{
Nslog (@ "applicationwillresignactive-> lose focus ");
}
# Pragma Mark called when the application enters the background (click the home key)
-(Void) applicationdidenterbackground :( uiapplication *) Application
{
Nslog (@ "applicationdidenterbackground-> enter the background ");
}
# Pragma Mark called when the application enters the foreground
-(Void) applicationwillenterforeground :( uiapplication *) Application
{
Nslog (@ "applicationwillenterforeground-> enter the foreground ");
}
# Pragma Mark called when the application gets the focus
-(Void) applicationdidbecomeactive :( uiapplication *) Application
{
Nslog (@ "applicationdidbecomeactive-> get focus ");
}
# The Pragma mark program is called when it is terminated in some cases
-(Void) applicationwillterminate :( uiapplication *) Application
{
Nslog (@ "applicationwillterminate-> terminate ");
}

@ End

Gpbviewcontroller. M file:
# Import "gpbviewcontroller. H"

@ Interface gpbviewcontroller ()
@ End

@ Implementation gpbviewcontroller

-(Ibaction) login {
Nsstring * name = _ name. text;
Nsstring * Pwd = _ PWD. text;

Nslog (@ "name = % @, password = % @", name, PWD );
// The view that calls out the keyboard is the first responder (firstresponder)
// Indicates this view. If you don't want to be the first responder, exit the keyboard.
// [_ Name resignfirstresponder];
// [_ PWD resignfirstresponder];

// If the first responder exists in self. view, you can exit the keyboard.
[Self. View endediting: Yes];
}

-(Void) viewdidload
{
[Super viewdidload];
// Do any additional setup after loading the view, typically from a nib.
}
-(Void) didreceivememorywarning
{
[Super didreceivememorywarning];
// Dispose of any resources that can be recreated.
}
@ End

 

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.