Open UIDatePicker programmatically in iOS 14

后端 未结 9 1553
南笙
南笙 2020-12-23 16:46

I have this normal UIDatePicker (sorry that it\'s not in English, please ignore that):

\"my

9条回答
  •  悲&欢浪女
    2020-12-23 17:33

    Unfortunately it's not possible to programatically display the date selector popup, at least not resorting to hacks that might result in your app being rejected:

    • the UIDatePicker control doesn't expose any events that can be programatically triggered via sendActions(for:) - allControlEvents returns an empty option set

    • programatically simulating a user click is officially impossible on iOS - there is no public API to achieve this, all workarounds imply resorting to private API's

    • if the above wouldn't be enough, the UI structure of UIDatePicker is composed of private classes:

    The conclusion is that in its current state, the UIDatePicker UI can be controlled only via user interactions. Maybe this will change in the future, for example UIButton's expose actions for triggering the same behaviour as when the user tapped the button, so maybe UIDatePicker will expose such actions in the future.

提交回复
热议问题