How to close DatePicker after selection in View?

I have a DatePicker in View not Viewcontroller. The solution in stack overflow works fine, if the DatePicker is in ViewController. (https://stackoverflow.com/questions/67109078/close-uidatepicker-after-selection-when-style-is-compact)

I want to close DatePIcker after selecting a date.

Thank you.

The picker is in a View, but isn't this View in a ViewController ?

How to close DatePicker after selection in View?
 
 
Q