문제

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 sharedApplication] 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top