[英]UITextField resignFirstResponder not working?
I've double checked all the connections in the nib file. 我已经仔细检查了nib文件中的所有连接。 My code -
我的代码-
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"iphone_bg_login.png"]];
self.title = @"Login screen";
loginTxt = [[UITextField alloc] init];
pwdText = [[UITextField alloc] init];
loginFailedTxt = [[UILabel alloc] init];
loginBtn = [[UIButton alloc] init];
navAppDelegate = (NavAppDelegate *)[[UIApplication sharedApplication] delegate];
navAppDelegate.navController.navigationBarHidden = YES;
//NSArray *subVs = (NSArray *) [self.view subviews];
[super viewDidLoad];
}
I've used a subclass of UIView (UIControl)
and added all the UI elements to it in the Interface builder.The UIControl's touchDown
method is connected to backgroundTap
method. 我使用了
UIView (UIControl)
的子类,并在“界面UIControl's touchDown
向其中添加了所有UI元素UIControl's touchDown
方法连接到backgroundTap
方法。
-(IBAction) backgroundTap:(id) sender {
[loginTxt resignFirstResponder];
[pwdText resignFirstResponder];
//[[UIApplication sharedApplication] becomeFirstResponder];
//[sender resignFirstResponder];
}
So the keyboard isn't removed like it's supposed to. 因此,并未像预期的那样卸下键盘。 Not sure why.
不知道为什么。
Thanks for the help! 谢谢您的帮助! Teja.
Teja公司。
DyingCactus has pointed to your error. DyingCactus指出了您的错误。 You're replacing the NIB-version of the control with a completely different control, losing your pointer to the one in the NIB.
您正在用完全不同的控件替换该控件的NIB版本,从而丢失了指向NIB中的指针的指针。 When you call
resignFirstResponder
, you're calling it on your duplicate object, not the one that's actually on the screen. 当您调用
resignFirstResponder
,您是在重复的对象上调用它,而不是在屏幕上实际的对象上调用它。 Get rid of the alloc
and init
calls for things wired in the NIB. 摆脱对NIB中连接的东西的
alloc
和init
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.