Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker and PickerView issues. #33

Open
SoolyChristy opened this issue Mar 26, 2018 · 7 comments
Open

DatePicker and PickerView issues. #33

SoolyChristy opened this issue Mar 26, 2018 · 7 comments

Comments

@SoolyChristy
Copy link

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

@dillidon
Copy link
Owner

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

@SoolyChristy
Copy link
Author

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

@dillidon
Copy link
Owner

@SoolyChristy what you mean? better attache image

@hardikamal
Copy link

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

@khemali-iOS
Copy link

khemali-iOS commented Jun 12, 2018

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

@jahid-hasan-polash
Copy link

jahid-hasan-polash commented Jul 31, 2018

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

@uclort
Copy link

uclort commented Aug 19, 2019

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)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants