//1.遵循协议UITextFieldDelegate
<span style="font-size:24px;">@interface AppDelegate : UIResponder <UIApplicationDelegate,UITextFieldDelegate></span>
//2.设置代理
<span style="font-size:24px;">self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen ].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UITextField *f = [[UITextField alloc]initWithFrame:CGRectMake(10, 100, 500, 150)];
f.borderStyle = UITextBorderStyleRoundedRect;
f.delegate = self; <span style="color:#FF0000;">//设置代理(此处为重中之重,不可忘记)</span>
f.placeholder = @"用户名/手机号/邮箱";
[self.window addSubview:f];
[f release ];
</span>
//实现协议中的方法
<span style="font-size:24px;">- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}</span>