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

Get Date or UIPickerView from alert to use in a select action #51

Open
wants to merge 1 commit into
base: new
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ alert.addDatePicker(mode: .dateAndTime, date: date, minimumDate: minDate, maximu
alert.addAction(title: "OK", style: .cancel)
alert.show()
```
Get the date in your action handler.
```swift
alert.addAction(title: "OK", style: .cancel) { _ in
let date = alert.dateFromDatePicker()
// action with selected date
}
```

## PickerView

Expand Down Expand Up @@ -242,6 +249,13 @@ alert.addPickerView(values: pickerViewValues, initialSelection: pickerViewSelect
alert.addAction(title: "Done", style: .cancel)
alert.show()
```
Get the picker in your action handler.
```swift
alert.addAction(title: "Done", style: .cancel) {
let picker = alert.pickerView()
// action with the picker view
}
```

## Locale Pickers

Expand Down
12 changes: 12 additions & 0 deletions Source/Pickers/Date/DatePickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ extension UIAlertController {
let datePicker = DatePickerViewController(mode: mode, date: date, minimumDate: minimumDate, maximumDate: maximumDate, action: action)
set(vc: datePicker, height: 217)
}

/// Returns the date from the datePicker
/// Author: Jahid Hasan Polash
/// InfancyIT
/// [email protected]
func dateFromDatePicker() -> Date? {
guard let datePickerVC = value(forKey: "contentViewController") as? DatePickerViewController
else {
return nil
}
return datePickerVC.datePicker.date
}
}

final class DatePickerViewController: UIViewController {
Expand Down
12 changes: 12 additions & 0 deletions Source/Pickers/PickerView/PickerViewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ extension UIAlertController {
let pickerView = PickerViewViewController(values: values, initialSelection: initialSelection, action: action)
set(vc: pickerView, height: 216)
}

/// Returns the picker view itself to extract data or index from it
/// Author: Jahid Hasan Polash
/// InfancyIT
/// [email protected]
func pickerView() -> UIPickerView? {
guard let pickerViewController = value(forKey: "contentViewController") as? PickerViewViewController
else {
return nil
}
return pickerViewController.pickerView
}
}

final class PickerViewViewController: UIViewController {
Expand Down