How do I dismiss the iOS keyboard?

后端 未结 16 1148
情书的邮戳
情书的邮戳 2020-11-29 20:00

I have a UITextfield that i\'d like to dismiss the keyboard for. I can\'t seem to make the keyboard go away no matter what code i use.

16条回答
  •  我在风中等你
    2020-11-29 20:14

    I've discovered a case where endEditing and resignFirstResponder fail. This has worked for me in those cases.

    ObjC

    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];    
    [self setEditing:NO];
    

    Swift

    UIApplication.shared.sendAction(#selector(resignFirstResponder), to: nil, from: nil, for: nil)
    

提交回复
热议问题