UITextField resignFirstResponder无法正常工作?

我已经仔细检查了nib文件中的所有连接。我的代码 -
// 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];
}
我使用了
UIView (UIControl)
的子类,并在Interface builder中添加了所有UI元素.
UIControl's touchDown
方法连接到
backgroundTap
方法。
-(IBAction) backgroundTap:(id) sender {
    [loginTxt resignFirstResponder];
    [pwdText resignFirstResponder];
    //[[UIApplication sharedApplication] becomeFirstResponder];
        //[sender resignFirstResponder];
} 
因此,键盘不会像预期的那样被移除。不知道为什么。 谢谢您的帮助! Teja公司。     
已邀请:
DyingCactus指出了你的错误。您将使用完全不同的控件替换控件的NIB版本,丢失指向NIB中的指针。当你拨打
resignFirstResponder
时,你在你的复制对象上调用它,而不是实际在屏幕上的对象。摆脱
alloc
init
呼叫NIB中有线的事情。     

要回复问题请先登录注册