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故障
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01