0

我有一种情况,我有一个警报视图,其中以编程方式绘制了一个文本字段

UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Enter you name" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

    nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];

    [nameField setBorderStyle:UITextBorderStyleRoundedRect];
    [nameField setPlaceholder:@"Enter Owners name"];
    [nameField setTextAlignment:UITextAlignmentCenter];
    [nameField setDelegate:self];
    [nameField setBackgroundColor:[UIColor clearColor]];

    [alertView addSubview:nameField];
    CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, -80.00);
    [alertView setTransform: moveUp];

    [alertView show];
    [alertView release];

隐藏我用过的键盘

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];
return YES;

}

但键盘并没有隐藏。请帮助我。

4

1 回答 1

4

您可以使用此隐藏键盘。这将在单击您的模拟器/模拟器/iOS 设备的背景时起作用。

  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

            [yourtextfield resignFirstResponder];

            // you can have multiple textfields here


        }
于 2011-05-02T12:51:37.680 回答