您好我正在尝试使用ActionSheetPicker让用户选择提醒时间但我收到标题中描述的错误。这是我的代码:
SelectTime(sender: validCell) // called when tapping a date
// Time Picker
func SelectTime(sender: UIView){
//let timePicker = ActionSheetDatePicker.show(withTitle: "Enter time for reminder", datePickerMode: .time, selectedDate: userDate, target: self, action: , origin: sender.superview!.superview)
let timePicker = ActionSheetDatePicker.show(withTitle: "Enter time for reminder", datePickerMode: .time, selectedDate: userDate, target: self, action: Selector(("timePicked")), origin: sender.superview!.superview, cancelAction: Selector(("timeCanceled")))
timePicker?.minuteInterval = 5
timePicker?.locale = Calendar.current.locale
timePicker?.show()
}
func timePicked(time: Date){
dateSelected.text = formatter.string(for: time)
}
func timeCanceled(){
print("Canceled")
dismiss(animated: true, completion: nil)
}
永远不会调用取消代码,当我在timePicker上按下取消时,它会在其下方显示另一个时间选择器而没有任何按钮。 Gif取消时 http://www.giphy.com/gifs/l1J3zMQWJ23GpHEaY
也永远不会调用dateSelected。我在选择错误吗?
答案 0 :(得分:1)
更改此代码
func SelectTime(sender: UIView){
let timePicker = ActionSheetDatePicker.show(withTitle: "Enter time for reminder", datePickerMode: .time, selectedDate: userDate, target: self, action: , origin: sender.superview!.superview)
let timePicker = ActionSheetDatePicker.show(withTitle: "Enter time for reminder", datePickerMode: .time, selectedDate: userDate, target: self, action: Selector(("timePicked")), origin: sender.superview!.superview, cancelAction: Selector(("timeCanceled")))
timePicker?.minuteInterval = 5
timePicker?.locale = Calendar.current.locale
timePicker?.show()
}
func timePicked(time: Date){
dateSelected.text = formatter.string(for: time)
}
func timeCanceled(){
print("Canceled")
dismiss(animated: true, completion: nil)
}
在此代码....
let timePicker = ActionSheetDatePicker(title: "Date:", datePickerMode: UIDatePickerMode.date, selectedDate: Date(), doneBlock: {
picker, value, index in
dateSelected.text = formatter.string(for: time)
print("value = \(value)")
print("index = \(index)")
print("picker = \(picker)")
return
}, cancel: { ActionStringCancelBlock in
print("cancel")
return }, origin: sender.superview!.superview)
timePicker?.minuteInterval = 5
timePicker?.locale = Calendar.current.locale