标签:ios
BeyondViewController.h
// // BeyondViewController.h // 01_calc // // Created by beyond on 14-7-20. // Copyright (c) 2014年 com.beyond. All rights reserved. // #import <UIKit/UIKit.h> @interface BeyondViewController : UIViewController // IBOutlet IBAction的唯一目的,就是让控制器的头文件中的这些成员属性和方法,能够出现在storyboard的右击列表里面 // 控制器定义好一个成员,等待界面上的控件来连接 @property (nonatomic,weak) IBOutlet UITextField *num1; @property (nonatomic,weak) IBOutlet UITextField *num2; @property (nonatomic,weak) IBOutlet UILabel *result; // 控制器定义好一个对象方法,等待界面上的按钮点击的时候来调用 (此处是声明) - (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];
}
#pragma mark - 监听按钮点击,计算结果
// 控制器定义好一个方法,等待界面上的按钮点击的时候来调用 (此处是实现)
- (IBAction)btnClick:(UIButton *)sender
{
// 当前控制器的成员view里面共有多少个儿子son控件
NSLog(@"当前控制器的成员view里面共有%d个儿子son控件",self.view.subviews.count);
// 计算结果的按钮tag是4
if (4==sender.tag) {
NSLog(@"点击了计算结果按钮 %@",sender);
// 1,直接使用下划线开头的成员变量名,2,使用self点语法
// UITextField *textField1=_num1;
NSString *n1=self.num1.text;
NSString *n2=self.num2.text;
NSLog(@"第1个数字是 %@ 第2个数字是 %@",n1,n2);
int result=[n1 intValue]+[n2 intValue];
self.result.text=[NSString stringWithFormat:@"%d",result];
}
switch ([sender tag]) {
case 1:
NSLog(@"点击了tag为1的按钮");
break;
case 2:
NSLog(@"点击了tag为2的按钮");
break;
default:
break;
}
// BeyondViewController
NSLog(@"self 是 %@",self);
[_num1 resignFirstResponder];
[_num2 resignFirstResponder];
}
@end
效果图
标签:ios
原文地址:http://blog.csdn.net/pre_eminent/article/details/38051875