iOS 中 textFieldShouldReturn 方法的使用
8月 31, 2014
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