Basics of iOS (i)

Source: Internet
Author: User

Recently found a position to contact iOS development, can learn and practice the system. Let's start with the basics:

One, two ways to get control

1) The first kind, which is also used frequently, is through the Iboutlet way. The control key is directly used to connect the controls to the Viewcontroller, and then the control can be obtained through the controller's properties.

2) The second type, by setting the control's Tag property.

Set the control's Tag property to a value of type integer, and then get the

1 UILabel *lbl2 = (uilabel*) [Self.view viewwithtag:2];

Ii. three ways to deal with events

1) First, the most commonly used is through the ibaction way

2) Second, set up event handling methods through code

Call AddTarget:action:forControlEvents in the Viewdidload event to add processing events.

AddTarget: Indicates that a method of the object has been changed to handle the event, such as the current controller

Action: Represents the method that handles the event

forControlEvents: The type of event to be processed, an enumeration value of Uicontrolevents

Example:

- (void) viewdidload{[Super Viewdidload]; NSLog (@"Page Loading Complete"); Appdelegate*ad = [UIApplication sharedapplication].Delegate; NSLog (@"the Lycname property of the print agent class%@", AD.        Lycname); //to add an event to a control[Self.btnmeet addtarget:self Action: @selector (Btnmeet_click:) forcontrolevents:uicontroleventtouchupinside];}-(void) Btnmeet_click: (UIButton *) sender{Uialertview*alertview = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"I'm meeting the button ."  Delegate: Nil Cancelbuttontitle:@"Determine"Otherbuttontitles:nil, nil]; [Alertview show];}

3) Handling events through delegate objects

Iii. creating controls from code

1. Creating UI Controls

2. Call Addsubview to add the created control to the other view

3. Call the control setter method multiple times, set the appearance, behavior, etc.

Example:

    // Create a control    with code UIButton *button = [UIButton buttonwithtype:uibuttontyperoundedrect];     // to set the size    of a button Button.frame=cgrectmake (+);    [Button Settitle: @" I was created by code " Forstate:uicontrolstatenormal];    [Self.view Addsubview:button];

Basics of iOS (i)

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.