IPhone: Can I make a UIDatePicker on top of a UIKeyboard?

What am I trying to do:

I have a standard UITableView, with several UITextFields and several cells showing time / date. Basically, this is a form in which users can enter both text and dates.

How it works:

  • At first, neither the keyboard nor the date selection is displayed.
  • If a text field is selected first, a keyboard will appear. And vice versa, to select a date (which appears with a similar animation).
  • If you initially selected a text field, and then the user selects a time cell, UIKayboard should turn into a date picker (without animation). Similarly, it should happen when the opposite.

What does not work:

Everything works fine - except for the last step mentioned above. Basically, I can't figure out how to represent anything on top of the keyboard.

My method was to animate both the keyboard and the date at the same time, but set the "hidden" property to select the date accordingly.

-

Any ideas on how I can add something in front of the keyboard? Can I create another window on top of everything right after adding a keyboard? Or use the accessoriesView property, but transpose the frame somehow?

Otherwise, are there any alternative ways to achieve my original goal?

Thanks:)

+4
source share
1 answer

Even easier than listening to keyboard notifications, is to understand that a UITextField is a subclass of UIResponder , which means it has an inputView property. You can simply create a UIDatePicker , set it as an inputView text field, and you're done. (plus all you have to do to actually retrieve the date from the collector).

The only drawback of this approach is that although it works very well for portrait orientation on the iPhone, you need to work a bit to make things look like in the landscape and on the iPad. However, this is the same thing that you have to do anyway.

+8
source

All Articles