【问题标题】:How to use an IBAction to write data to Firebase如何使用 IBAction 将数据写入 Firebase
【发布时间】:2017-04-26 01:12:20
【问题描述】:

我无法弄清楚如何通过 IBAction 将数据写入我的 Firebase 数据库。

我的问题是无法写入实际数据库,这是正在写入的数据类型。

我需要使用 Google Maps Services Place 对象写入数据。这是我的数据库编写代码:

let newWaitTime = Int(waitTimeLabel.text!)

let waitTime = databaseRef.child("times").child(place.placeID).childByAutoId()

waitTime.setValue(newWaitTime)

问题是因为IBAction 函数不能接受其他参数,我不能将我的place 变量传递到函数中以允许我写入我的数据库。

我似乎无法找到解决方法,因为它需要知道place.placeID 才能提交时间。没有它,就无法区分哪个时间属于哪个地方。有什么想法吗?

【问题讨论】:

    标签: ios swift firebase firebase-realtime-database gmsplace


    【解决方案1】:

    在主类中添加以下内容

    var currentPlace: Place?
    

    那么每当你与某个地方互动时

    self.currentPlace = placeImInteractingWith
    

    在 IBAction 中

    if let placeToUse = currentPlace {
        let waitTime = databaseRef.child("times").child(placeToUse.placeID).childByAutoId()
        //etc
    {
    

    【讨论】:

    • 即便如此,我仍然收到以下错误*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Crunch_Time_Real.cardView submitButtonPressed:place:]: unrecognized selector sent to instance 0x102152eb0' ***
    猜你喜欢
    • 2022-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    相关资源
    最近更新 更多