I have a text field in my UI that when it's selected presents a UIDatePicker instead of the default keyboard, how could I set up a button as to dismiss the picker when the user is done?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
Create a UIView (namely customDatePickerView) and in that view ,create datepicker and a done button and a cancel button in the xib. In the textfield delegate:
Function on Date Picker Value Changed
Hope this will help you.
What I do is have my inputView as a custom view which contains a
UIDatePicker
and a toolbar above it with a 'Done' button wired up to a method that calls a delegate method to tell the object that owns theUITextField
to dismiss the "keyboard" by callingresignFirstResponder
.I've done a similar thing where I've created a view with a button and the
UIDatePicker
, then presented that view instead of theUIDatePicker
alone. Then the button is just connected to anIBAction
that moves the view out.This way, the button moves in with the
UIDatePicker
view and they look "connected" to the user. You can even define thisUIView
in your nib and useaddSubview:
at runtime.You can solve this by adding this
Add this where you want to dismiss date picker like i have added this on tap gesture
On viewDidLoad added a Tapgesture
After adding this on viewdidLoad Add this method to detect gesture recognizer