iOS 中 textFieldShouldReturn 方法的使用

iOS 中 textFieldShouldReturn 方法的使用

Aug 31, 2014
Objc

iOS 中 textFieldShouldReturn 方法定义在 UITextFieldDelegate 协议中

//  ViewController.m


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (textField==_name) {
        [_passwd becomeFirstResponder];
    }else if(textField==_passwd){
        [self login:nil];
    }
    return YES;
}

- (IBAction)login:(id)sender {
    [self.view endEditing:NO];
    NSString *name = _name.text;
    NSString *passwd = _passwd.text;
    [_lable setText:[NSString stringWithFormat:@"username:%@ password:%@",name,passwd]];
    }
@end

img

本文以 CC 署名-非商业性使用-禁止演绎 4.0 国际 协议进行许可。

上一篇:数据结构与算法实验课 - 链表

下一篇:iOS 中添加按钮和按钮监听方法