ios - 单击一个按钮将多个数据行发送到 firebase

标签 ios swift xcode firebase

伙计们<3 这是我使用 firebase 的第一个项目,我想向数据库发送大量数据,问题是当我单击按钮时,只有最后一行代码被发送,我也尝试过但函数中的每一行并调用它们一个接一个,同样的情况发生,只有最后一个函数起作用并发送数据,这是点击代码上的按钮

    @IBAction func Send(_ sender: Any) {
    apperfun();
    dnamefun();
    docfun();
    servfun();
    pnamefun();
    pnumfun();
}

这是函数

func apperfun() {
    if ap == "1" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Excellent"])}
    else if ap == "2" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Good"])}
    else if ap == "3" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Bad"])}
}

func dnamefun() {
    self.ref.child("fullinfo").child(pname).setValue(["dname":dname])
}

func docfun() {
    if doc == "1" {self.ref.child("fullinfo").child(pname).setValue(["level": "Excellent"])}
    else if doc == "2" {self.ref.child("fullinfo").child(pname).setValue(["level": "Good"])}
    else if doc == "3" {self.ref.child("fullinfo").child(pname).setValue(["level": "Bad"])
        self.ref.child("bad").child(pname+phone).setValue(["level": "Bad"])}
}

func servfun() {
    if serv == "1" {self.ref.child("fullinfo").child(pname).setValue(["performance": "Excellent"])}
    else if serv == "2" {self.ref.child("fullinfo").child(pname).setValue(["performance": "Good"])}
    else if serv == "3" {self.ref.child("fullinfo").child(pname).setValue(["performance": "Bad"])}
}

func pnamefun() {
    self.ref.child("fullinfo").child(pname).setValue(["pname":pname]);
}

func pnumfun() {
    self.ref.child("fullinfo").child(pname).setValue(["pnum":phone]);
}
    func receptionfun() {
        if recep == "1" {self.ref.child("fullinfo").child(pname).setValue(["reception": "Excellent"])}
        else if recep == "2" {self.ref.child("fullinfo").child(pname).setValue(["reception": "Good"])}
        else if recep == "3" {self.ref.child("fullinfo").child(pname).setValue(["reception": "Bad"])}
    }

最佳答案

setValue 会将该节点中的任何数据替换为您正在设置的数据。您想要使用更新。更新将替换 key (如果存在),或者将其添加到您的数据库(如果不存在)。

你有这个:

if ap == "1" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Excellent"])}

应该是:

if ap == "1" {self.ref.child("fullinfo").child(pname).updateChildValues(["apperance": "Excellent"])}

关于ios - 单击一个按钮将多个数据行发送到 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45514305/

相关文章:

iphone - 如何改变 UITableView 的外观?

ios - 将 Action Segue 从按钮推送到 UIViewController

html - NSAttributedString 从 HTML 暗模式初始化,如何设置默认前景色?

ios - Swift:UIScrollView 不垂直滚动

ios - 如何在 Swift 中生成和处理错误

ios - 通过点击 TableView 单元格将数据传递到详细 View

iphone - 如何禁用弹出菜单项,如选择、全选、建议...、定义(在 UIWebView 上)?

ios - 将文件加载到应用程序本地存储

ios - 测试在 Xcode 的问题导航器中消失

iphone - 通过didReceive数据导入图片