1

您好我正在尝试使用 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 也永远不会被调用。我做错了选择器吗?

4

1 回答 1

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
于 2017-07-29T08:58:42.270 回答