【问题标题】:Retrieve Firebase object by key按键检索 Firebase 对象
【发布时间】:2016-05-26 18:53:03
【问题描述】:

我正在使用 Geofire 来存储项目及其位置。

为了检索特定区域内的项目,我使用 Geofire 的地理查询:

 var queryHandle = query.observeEventType(.KeyEntered, withBlock: {(key: String!, location: CLLocation!) in
  println("Key '\(key)' entered the search area and is at location '\(location)'")
 })

正如预期的那样,结果是指定区域中的键 - 我的问题是:我如何获取实际对象以便访问它具有的其余属性?

我将所有这些都作为 UITableView 的一部分,因为我想在表格中(以及稍后在地图上)呈现我附近的对象

任何使用 geofire 填充 UITableView 的最佳实践都将受到赞赏。

谢谢!

【问题讨论】:

标签: swift uitableview firebase geofire


【解决方案1】:

您可以简单地创建一个值单个事件并读取该值。 Firebase 足够快速和高效地读取它,并且它可以与 UITableViews 和 UICollectionViews 一起正常工作,完全没有问题。


    //ref is the reference to your object's parent path, and key is the value you received with the geofire query
    ref.childByAppendingPath(key).observeSingleEventOfType(.Value, withBlock: {       
       (snapshot:FDataSnapshot!) in

        //The snapshot has the data of your actual object        

    })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    相关资源
    最近更新 更多