如何在不从firebase获取值的情况下读取父节点名称对于ios? [英] How to read the parent node name without getting value from firebase For ios?

查看:145
本文介绍了如何在不从firebase获取值的情况下读取父节点名称对于ios?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读餐厅名称汉堡王吃点使用swift。

I want to read the restaurant names Burger King, Eating Point using swift.

如何才有可能,任何人都可以帮助我,这是因为我的最终项目需要在1周内提交,请我输了希望这个

How it can be possible, Can anyone help me please this is for my final project need to submit in 1 week please i'm losing hope with this

 ref = Database.database().reference()

    ref?.child("Restaurants").observe(.childAdded, with: { (snapshot) in
        let rest = snapshot.value as? String
        if let actualPost = rest {


            self.restList.append(actualPost)

            print("list of rest ", self.restList)


            self.restTableView.reloadData()
        }
    })


推荐答案

仅获取餐馆名称低于代码。

To get only restaurant names use below code.

dbReference = Database.database().reference()
dbReference?.child("Restaurants").observeSingleEvent(of: .value, with: {(snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
            print("Restaurant Name:\(rest.key)")
        }

})

使用StoryboardId传递所有数据使用下面的代码。

And to pass all data using StoryboardId use below code.

dbReference = Database.database().reference()
dbReference?.child("Restaurants").observeSingleEvent(of: .value, with: {(snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
            print("Restaurant Data:\(rest)")

        }

})

把它放在
中并在destinationController中声明数据变量,如下所示:

Put this in your And declare data variable in destinationController like below:

var data = [DataSnapshot]()

你必须从didselectRow执行这样的讨论。

You have to performsegue from didselectRowAt like this.

performSegue(withIdentifier: "segue", sender: self)

您可以从以下功能传递所选项目的数据。

And you can pass the data of selected item from the below function.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let index = CategorytableView.indexPathForSelectedRow
let indexNumber = index?.row
print(indexNumber!)
let VC = segue.destination as! DestinationVC
VC.data = [rest] . //You can pass here entire data of selected row.

}

这篇关于如何在不从firebase获取值的情况下读取父节点名称对于ios?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆