ResignFirstResponder doesn't dismiss the keyboard (iPhone)

后端 未结 6 1013
情话喂你
情话喂你 2020-12-16 04:06

I\'ve searched through this site that I couldn\'t find a solution to the problem I\'m facing now. Hope someone can help.

I\'ve created a UIAlertView to prompt user

相关标签:
6条回答
  • 2020-12-16 04:45

    What happens if you move the releasing of the text field to the delegate method, after you call the resignFirstResponder method?

    0 讨论(0)
  • 2020-12-16 04:46

    simply do

    [mytextField addTarget:self 
                action:@selector(methodToFire:)
                forControlEvents:UIControlEventEditingDidEndOnExit];
    
    0 讨论(0)
  • 2020-12-16 04:53

    if anyone is having trouble with this in storyboard i had to go into my uitextfields properties and ctrl+drag from its delegate to its root view controller all in storyboard and that fixed everything..

    0 讨论(0)
  • 2020-12-16 04:58

    First you need to define your enterNameAlert in interface header. then use the below code.

    - (void)viewDidLoad {    
        [super viewDidLoad];
        enterNameAlert = [[UIAlertView alloc] initWithTitle:@"Enter your name"
                                                                 message:@"\n\n\n"
                                                                delegate:self
                                                       cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
                                                       otherButtonTitles:NSLocalizedString(@"OK", nil),nil];
    
        UITextField *enterNameField = [[UITextField alloc] initWithFrame:CGRectMake(16, 83, 252, 25)];
        enterNameField.keyboardAppearance = UIKeyboardAppearanceAlert;
        enterNameField.borderStyle = UITextBorderStyleRoundedRect;
        enterNameField.autocorrectionType = UITextAutocorrectionTypeNo;
        enterNameField.clearButtonMode = UITextFieldViewModeWhileEditing;
        enterNameField.returnKeyType = UIReturnKeyDone;
        enterNameField.delegate = self;    
        [enterNameAlert addSubview:enterNameField];
        [enterNameField becomeFirstResponder];
        [enterNameAlert show];    
        [enterNameField release];
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        if ([textField isFirstResponder]) {
            [textField resignFirstResponder];
            [enterNameAlert dismissWithClickedButtonIndex:1 animated:YES];
            [enterNameAlert release];
            NSLog(@"text field was first responder");
        } else {
            [textField becomeFirstResponder];
            [textField resignFirstResponder];
            NSLog(@"text field was not first responder");
        }
        NSLog(@"textfieldshouldreturn");
        return YES;
    }
    
    0 讨论(0)
  • 2020-12-16 04:58

    Have another object become and then immediately resign the first responder.

    0 讨论(0)
  • 2020-12-16 05:04

    Try dismissing keyboard using resignFirstResponder on "DidEndOnExit" event of your TextField.

    Then try to dismiss keyboard by pressing Done button on keyboard when you have finished entering the data into your TextField.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题