alerts-and-pickers icon indicating copy to clipboard operation
alerts-and-pickers copied to clipboard

DatePicker and PickerView issues.

Open SoolyChristy opened this issue 6 years ago • 7 comments

if picker values don't change, it will not call Action

SoolyChristy avatar Mar 26 '18 08:03 SoolyChristy

@SoolyChristy right) You want to call Action not to changing the picker? For what?

dillidon avatar Mar 28 '18 09:03 dillidon

if pick first option how i can get the value? @dillidon pick first option Action will not be called

SoolyChristy avatar Mar 28 '18 12:03 SoolyChristy

@SoolyChristy what you mean? better attache image

dillidon avatar Mar 28 '18 16:03 dillidon

@dillidon How can I get the selected date on Done button click in alertcontroller?

hardikamal avatar Jun 05 '18 14:06 hardikamal

I am having the same issue. How can I get the selected value in picker view(Without scrolling) after presenting the alert controller for the first time?

Please suggest something

khemali-iOS avatar Jun 12 '18 07:06 khemali-iOS

Very simple solution here.

  1. Make a function that returns the value or the picker itself in an extension of UIAlertController
  2. You can get the DatePickerViewController or PickerViewController by value(forKey: "contentViewController") function
  3. add an action to your alertController and in the handler revoke the values from the function. Will make a merge request for it. 😃 Example Code

jahid-hasan-polash avatar Jul 31 '18 11:07 jahid-hasan-polash

private func selectDate(_ handler: @escaping ((TimeInterval) -> Void)) {
        var dateTimeInterval: TimeInterval = 0
        let alert = UIAlertController(style: .actionSheet)
        alert.addDatePicker(mode: .date, date: nil, minimumDate: nil, maximumDate: nil) { (date) in
            dateTimeInterval = date.timeIntervalSince1970
        }
        alert.addAction(title: "确定", style: .cancel) { (_) in
            handler(dateTimeInterval)
        }
        present(alert, animated: true, completion: nil)
    }

uclort avatar Aug 19 '19 05:08 uclort