iPhone:键盘没有隐藏

发布于 2024-11-04 17:50:46 字数 959 浏览 6 评论 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;

}

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

I have a situation, I have an alertview with one textfield drawn in it programmatically

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];

to hide the keyboard I have used this

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

[textField resignFirstResponder];
return YES;

}

but keyboard is not hiding. Please help me in this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2024-11-11 17:50:46

您可以使用它隐藏键盘。当单击模拟器/仿真器/iOS 设备的背景时,这将起作用。

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

            [yourtextfield resignFirstResponder];

            // you can have multiple textfields here


        }

You can hide your keyboard using this. This will work when clicking the background of your simulator/emulator/iOS-device.

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

            [yourtextfield resignFirstResponder];

            // you can have multiple textfields here


        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文