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)