iPhone keyboard, Done button and resignFirstResponder

后端 未结 5 1843
无人及你
无人及你 2020-12-08 01:54

This is probably a dumb question, but I can\'t find the answer in the docs. Did the \"Done\" button on the pop-up keyboard always cause the keyboard to disappear? I see a lo

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 02:22

    In Xcode 5.1

    Enable Done Button

    • In Attributes Inspector for the UITextField in Storyboard find the field "Return Key" and select "Done"

    Hide Keyboard when Done is pressed

    • In Storyboard make your ViewController the delegate for the UITextField
    • Add this method to your ViewController

      -(BOOL)textFieldShouldReturn:(UITextField *)textField
      {
          [textField resignFirstResponder];
          return YES;
      }
      

提交回复
热议问题