使用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];
    
}

posted @ 2012-12-04 15:02  rui90102  阅读(195)  评论(0编辑  收藏  举报