iPhone: Resign Keyboard with Done button action with XIB

后端 未结 4 845
执笔经年
执笔经年 2020-12-21 00:38

hi i am working on UITextview

how to Resign Keyboard, after keyboard \"Done button\" click Action, which XIB

Thank you

相关标签:
4条回答
  • 2020-12-21 01:15

    hi if you want answer for, Resign the keyboard of UITextview with default "Done" button on keyboard, then this is answer for that

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
    replacementText:(NSString *)text {
    
        // Any new character added is passed in as the "text" parameter
    
        if([text isEqualToString:@"\n"]) {
    
            // Be sure to test for equality using the "isEqualToString" message
    
            [textView resignFirstResponder];
    
            // Return FALSE so that the final '\n' character doesn't get added
    
            return NO;
        }
    
        // For any other character return TRUE so that the text gets added to the view
    
        return YES;
    }
    

    i followed this to resign keyboard of UITextview, if there is any concern inform me

    Thank You

    0 讨论(0)
  • 2020-12-21 01:25

    To assign the action to the Done button of a keyboard:

    In these examples, myTextView is a UITextView that is defined in the header and connected in Interface Builder.

    -(BOOL)textViewShouldReturn:(UITextView*)textView {
        if (textView == myTextView) {
            [textView resignFirstResponder];
        }
        return YES;
    }
    

    To assign it to an external button:

    Be sure to define an IBAction in your header, then in Interface Builder, connect the button to this action for touchUpInside:

    .h

    -(IBAction)dismissKeyboard:(id)sender;
    

    .m

    -(IBAction)dismissKeyboard:(id)sender {
    
        [myTextView resignFirstResponder];
    
    }
    
    0 讨论(0)
  • 2020-12-21 01:25

    Call resignFirstResponder on the textview that has focus in order to dismiss the keyboard.

    0 讨论(0)
  • 2020-12-21 01:39

    Create an IBAction and in IB hook it up to the UITextfield's DidEndOnExit event. Then call the [textViewName resignFirstResponder] to make the keyboard go away.

    Alternatively, try using [self.view endEditing:YES] in the IBAction.

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