首页 > 代码库 > (5.17)QQ登入视图

(5.17)QQ登入视图

//  ViewController.h
//  qq登入器
//
//  Created by pg on 14-5-17.
//  Copyright (c) 2014年 mqd. All rights reserved.
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate>


//定义输入账号
@property (weak, nonatomic) IBOutlet UITextField *inNum;
//定义输入密码
@property (weak, nonatomic) IBOutlet UITextField *inCode;
//定义按钮
- (IBAction)button:(UIButton *)sender;
//定义消息输出框
@property (weak, nonatomic) IBOutlet UILabel *outmessage;
@end


 

//  ViewController.m
//  qq登入器
//
//  Created by pg on 14-5-17.
//  Copyright (c) 2014年 mqd. All rights reserved.



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


#pragma mark - button方法
- (IBAction)button:(UIButton *)sender {
    //创建输入账号对象
    NSString *num = [_inNum text];
    //创建输入密码对象
    NSString *code = [_inCode text];
    //创建并格式化消息对象
    NSString *messages = [NSString stringWithFormat:@"消息:\n账号:%@\n密码:%@",num,code];
    //调用uitextField的text方法实现数据传输
    [_outmessage setText:messages];
    
    //自动隐藏键盘
    [self.view endEditing:YES];
    
}

//设置textField的回传代理
#pragma mark - 代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    //用户光标在上一输入框内,接受到enter则调用次方法传递响应者令牌
    if (textField == _inNum) {
        [_inCode becomeFirstResponder];
    }else if(textField == _inCode){
        //调用button方法实现数据处理,nil无需返回值
        [self button:nil];
      }
    return YES;

}

@end