【问题标题】:Retrieve Firebase data to label检索要标记的 Firebase 数据
【发布时间】:2016-05-12 16:34:59
【问题描述】:

我正在尝试检索 firebase 信息并将其显示在标签中。

// Get a reference to our posts
Firebase *ref = [[Firebase alloc] initWithUrl:@"**************firebaseio.com/"];

// Attach a block to read the data at our posts reference
[ref observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snap) {

  NSLog(@"%@", snap.value);

} withCancelBlock:^(NSError *error) {

NSLog(@"%@", error.description);

}];

我已尝试添加 _label.text = snap.value,但由于某种原因,该应用程序仍然不断崩溃。

我需要检索大量信息,但对于此测试,我只想检索数据库中的唯一内容。在 NSLOG 中,我可以看到从数据库中检索到的值,但似乎无法将值放在标签中。

【问题讨论】:

  • 这是一个简单的解决方法,但您能否发布您的 Firebase 结构,以便我们使用与您的结构匹配的代码来回答?请将其发布为文本(无图像),可以通过 Firebase 仪表板->导出按钮获取

标签: ios firebase


【解决方案1】:

所有需要做的就是将 snapshot.value 转换为 NSString 然后转换为标签。

Firebase *ref = [[Firebase alloc] initWithUrl: @"*************firebaseio.com/"];

[ref observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snap) {
    // do some stuff once

    //        NSLog(@"%@", snap.value);

    string1 = snap.value;


    _shown.text = string1;
    NSLog(@"%@", _shown.text);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 2019-06-16
    • 2016-10-02
    • 1970-01-01
    相关资源
    最近更新 更多