我正在尝试使用 prepareForSegue
将 datePicker
的值从一个 VC 发送到另一个是我发送类的代码:
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)
}
最佳答案
关于ios - 为什么我在使用 prepareForSegue 传递值时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42935591/