IOS_1 _ Divider
BeyondViewController. h
//// BeyondViewController. h // 01_calc /// Created by beyond on 14-7-20. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
@ Interface BeyondViewController: UIViewController // the unique purpose of IBOutlet IBAction is to make these member attributes and methods in the Controller header file, it can appear in the right-click list of storyboard. // The controller defines a member and waits for controls on the interface to connect to @ property (nonatomic, weak) IBOutlet UITextField * num1; @ property (nonatomic, weak) IBOutlet UITextField * num2; @ property (nonatomic, weak) IBOutlet UILabel * result; // The controller defines an object method, wait for the button to be clicked on the interface (here is the declaration)-(IBAction) btnClick :( UIButton *) sender; @ end
BeyondViewController. m
//// BeyondViewController. m // 01_calc /// Created by beyond on 14-7-20. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondViewController. h "@ interface BeyondViewController () @ end @ implementation BeyondViewController-(void) viewDidLoad {[super viewDidLoad];} # click The pragma mark-listener button, computing Result // The controller defines a method and waits for the button on the interface to be called (implemented here)-(IBAction) btnClick :( UIButton *) sender {// Number of son controls in the view of the current controller member NSLog (@ "% d son controls in the view of the current controller member", self. view. subviews. count); // The tag of the calculated button is 4 if (4 = sender. tag) {NSLog (@ "click the calculation result button % @", sender); // 1. Name of the member variable starting with an underscore, 2, use the self point syntax // UITextField * textField1 = _ num1; NSString * n1 = self. num1.text; NSString * n2 = self. num2.text; NSLog (@ "1st digits: % @ 2nd digits: % @", n1, n2); int result = [n1 intValue] + [n2 intValue]; self. result. text = [NSString stringWithFormat: @ "% d", result];} switch ([sender tag]) {case 1: NSLog (@ "click the button with tag 1"); break; case 2: NSLog (@ "click the button with tag 2"); break; default: break ;} // BeyondViewController NSLog (@ "self is % @", self); [_ num1 resignFirstResponder]; [_ num2 resignFirstResponder];} @ end