开发者

UITextField resignFirstResponder not working?

I've double checked all the connections in the nib file. 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.

-(IBAction) backgroundTap:(id) sender {
    [loginTxt resignFirstResponder];
    [pwdText resignFirstResponder];
    //[[UIApplication sharedApplicati开发者_如何转开发on] becomeFirstResponder];
        //[sender resignFirstResponder];
} 

So the keyboard isn't removed like it's supposed to. Not sure why.

Thanks for the help! Teja.


DyingCactus has pointed to your error. You're replacing the NIB-version of the control with a completely different control, losing your pointer to the one in the NIB. When you call resignFirstResponder, you're calling it on your duplicate object, not the one that's actually on the screen. Get rid of the alloc and init calls for things wired in the NIB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜