开发者

iPhone: Can I make a UIDatePicker appear on top of a UIKeyboard?

What I'm trying to do:

I've got a standard UITableView, with several UITextFields and a few cells showing a time/date. Basically, it's a form where users can input both text and dates.

How it's meant to work:

  • At first, neither the keyboard or date picker is shown.
  • If a text field is selected first, the keyboard pops up. Vice versa for a date picker (which pops up with a similar animation).
  • If originally a text field was selected, and then the user selects a time cell, the UIKayboard should turn into a date picker (no animation). Likewise should happen when the other way around.

What's not working:

Everything works great - except for the last step I list开发者_JAVA百科ed above. Basically, I can't figure out how to present anything on top of the keyboard.

My method was just to animate both the keyboard/date up at the same time, but set the 'hidden' property for the date picker accordingly.

-

Any ideas as to how I might add something in front of the keyboard? Could I create another window on top of everything just after adding the keyboard? Or, use the accessoryView property but transpose the frame somehow?

Otherwise, are there any alternate ways I could achieve my original goal?

Thanks :)


Even easier than listening for the keyboard notifications is to realize that UITextField is a subclass of UIResponder, which means it has an inputView property. You can simply create a UIDatePicker, set it to be your textfield's inputView, and you're done. (plus anything you need to do to actually extract the date from the picker).

The only downside of this approach is that while it works extremely well for the portrait orientation on iPhone, you'll need to do a bit of work getting things to look right in landscape and on the iPad. However, it's the same sort of stuff you'd have to do anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜