ios - 为什么我在使用 prepareForSegue 传递值时出错?

标签 ios swift

我正在尝试使用 prepareForSeguedatePicker 的值从一个 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)

    }

最佳答案

我制作了一个演示项目来演示如何使用 segue 传递日期。克隆我的项目:

https://github.com/Hapeki/Example1

注意 Storyboard中的 segue 标识符。

关于ios - 为什么我在使用 prepareForSegue 传递值时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42935591/

相关文章:

ios - 为什么我在检查发件人的类别时收到错误 "Cannot assign to the result of this expression"?

ios - 如何在 `Quick Help` 的 Swift 注释中添加新行

Swift 4 + Alamofire 可解码 Json URL 格式

ios - JSON AnyObject 到 Bool 的转换总是返回 nil

ios - 如何使用消息 "outlined copy of Optional"调试崩溃?

iphone - 带有 Open GL ES 的 UIKit 粒子系统?

ios - 缓慢的 Swift 字符串性能

ios - 如何发送带有媒体附件的 ios 推送通知 (Azure Notif Hub)?

swift - 在 swift 中创建一个 16 字节的零数组

objective-c - iOS上图像的人脸二维失真? (类似于 Fat Booth 等)