iOS dismissing keyboard, UILabel malfunction(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故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS关闭键盘,UILabel故障
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
