我正在尝试使用datePicker
将prepareForSegue
的值从一个VC发送到另一个VC为什么我会收到错误,说“在解包可选值时找到nil”这里是我发送类的代码:
var dateSender: Date!
@IBAction func sendDate(_ sender: UIDatePicker) {
dateSender=datePicker.date
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var DateViewController: Viola=segue.destination as! Viola
DateViewController.HereDate=dateSender
}
接收课程的代码:
var HereDate: Date?
weak var reminder: Reminder?
@IBAction func `switch2`(_ sender: BEMCheckBox) {
let name = "hello"
var time1 = HereDate
let timeInterval = floor((time1?.timeIntervalSinceReferenceDate)!/60)*60
time1 = Date(timeIntervalSinceReferenceDate: timeInterval)
let notification = UILocalNotification()
notification.alertTitle = "Reminder"
notification.alertBody = "You need to \(name)!"
notification.fireDate = HereDate
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.shared.scheduleLocalNotification(notification)
reminder = Reminder(name: name, time: time1!, notification: notification)
}
答案 0 :(得分:1)
答案 1 :(得分:0)
我假设您两个 IBAction
和segue
与您的日期选择器相关联?
删除@IBAction func sendDate()
功能(并将其与日期选择器断开连接)。
在prepare(for segue:)
中,只需执行以下操作:
DateViewController.HereDate = datePicker.date