使用Done键关闭文本字段键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
-(void) viewDidLoad
{
self.title=@"Keyboard Dismissal";
UITextField *tf=(UITextField *)[self.view viewWithTag:101];
tf.delegate=self;
tf=[[UITextField alloc] initWithFrame:CGRectMake(0.0f,0.0f,100.0f,30.0f)];
tf.center=CGPointMake(160.0f,120.0f);
tf.borderStyle=UITextBorderStyleRoundedRect;
tf.autocorrectionType=UITextAutocorrectionTypeNo;
tf.placeholder=@"Name";
tf.returnKeyType=UIReturnKeyDone;
tf.clearButtonMode=UITextFieldViewModeWhileEditing;
tf.delegate=self;
[self.view addSubview:tf];
[tf release];
}