Hi I have a requirement where I need to show date in uiactionsheet
getting Error While using Date picker class ActionSheetDatePicker.init
As far as I know there are no class named ActionSheetDatePicker
in Apple's framework. Can you tell me how it is defined?
And showing teared fragments of code would not be helpful to find what's going on. Can you show whole class(es) or method(s) in one piece?
`// SignupViewController.swift
import UIKit
import SwiftValidator
class SignupViewController: BaseViewController {
@IBOutlet weak var dobTextField: UITextField!
var viewModel = SignUpViewModel()
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension SignupViewController:UITextFieldDelegate {
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField == dobTextField {
self.view.endEditing(true)
super.datePickerTapped { (dateString) in
self.dobTextField.text = dateString
}
return false
}
return true
}
}`
`// BaseViewController.swift
import UIKit
import NVActivityIndicatorView
import Toast_Swift
import ActionSheetPicker_3_0
import TweeTextField
import SwiftValidator
class BaseViewController: UIViewController {
func datePickerTapped(completionHandler: @escaping ((String)->Void)) {
let cancelButton:UIButton = UIButton(type: .custom)
cancelButton.setTitle("Cancel", for: .normal)
cancelButton.titleLabel?.font = crudFonts.appRegularFont
cancelButton.setTitleColor(UIColor.black, for: .normal)
cancelButton.frame = CGRect(x: 0, y: 0, width: 55, height: 25)
let doneButton:UIButton = UIButton(type: .custom)
doneButton.setTitle("Done", for: .normal)
doneButton.titleLabel?.font = crudFonts.appRegularFont
doneButton.setTitleColor(UIColor.black, for: .normal)
doneButton.frame = CGRect(x: 0, y: 0, width: 55, height: 25)
let maxiumDate = Calendar.init(identifier: Calendar.Identifier.gregorian).date(byAdding: .year, value: -18, to: Date())
let picker = ActionSheetDatePicker.init(title: "Date of Birth", datePickerMode: .date, selectedDate: maxiumDate, doneBlock: { (picker, selectedIndex, selectedValue) in
if let date = selectedIndex as? Date {
let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/YYYY"
completionHandler(formatter.string(from: date))
}
}, cancel: { (picker) in
}, origin: Global.getTopMostViewController()?.view)
picker?.minimumDate = Calendar.init(identifier: Calendar.Identifier.gregorian).date(byAdding: .year, value: -100, to: Date())
picker?.maximumDate = maxiumDate
picker?.toolbarButtonsColor = .black
picker?.toolbarBackgroundColor = UIColor.white
picker?.setCancelButton(UIBarButtonItem(customView: cancelButton))
picker?.setDoneButton(UIBarButtonItem(customView: doneButton))
picker?.show()
if let datePicker = picker?.pickerView as? UIDatePicker {
if #available(iOS 13.4, *) {
datePicker.preferredDatePickerStyle = UIDatePickerStyle.wheels
}
}
}
}`
@OOper its a CocoaPods library Which I`ve use for date picker and ActionSheetDatePicker class of this library
library link :- https://cocoapods.org/pods/ActionSheetPicker
Thanks for showing your code. But codes in comments cannot be properly formatted and hard to read. Can you use Your Answer to show your code? (Please format it as Code Block, not Add Text.)