iOS关闭键盘,UILabel故障

时间:2023-03-07
本文介绍了iOS关闭键盘,UILabel故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发的 iOS 应用程序中遇到了几个问题.

I'm running into a couple problems in the iOS app I'm developing.

一个正在关闭键盘:当它在另外两个屏幕上工作时,有一个屏幕由于某种原因不会关闭:

One is dismissing the keyboard: while it works on another two screens, there's one screen where it won't dismiss for some reason:

Login.m

#import "Login.h"

@interface Login()
@end

@implementation Login

-(void) viewdDidLoad{

     [super viewDidLoad];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                action:@selector(dismissKeyboard)];

    [self.view addGestureRecognizer:tap];


}

-(void)dismissKeyboard {
    [_username resignFirstResponder];
    [_password resignFirstResponder];
    [_birth resignFirstResponder];
}

@end

我的第二个问题是,尽管在其他屏幕上工作,但屏幕顶部的 UILabel 不会加载:

And my second problem is that the UILabel at top the screen won't load despite working in the other screens:

Login.m

#import "Login.h"

@interface Login()
@end

@implementation Login

-(void) viewdDidLoad{

     [super viewDidLoad];

    _etiqueta = @"Introdueix el teu nom d'usuari, la contrasenya, i la teva data de naixement";
    self.label.text = self.etiqueta;
    self.label.numberOfLines = 4;
    self.label.textColor = [UIColor blackColor];

}


@end

我的 UILabel 也是在情节提要上创建的,它是 IBOutlet,我已确保它已正确链接.

My UILabel is created on the storyboard as well, is IBOutlet and I've made sure that it's properly linked.

你能帮我解决这两个问题吗?

Can you help me solve these 2 problems?

推荐答案

使用这个方法关闭键盘

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}

否则调用textDelegate方法

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

[textField resignFirstResponder];
return YES;
 }

这篇关于iOS关闭键盘,UILabel故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:即使 UIResponder 对象放弃它的第一响应者状态,键 下一篇:隐藏在键盘下的 SKStoreReviewController 按钮

相关文章

最新文章