如何将快照数据分配给标签?斯威夫特2&火力地堡

时间:2016-05-02 20:41:23

标签: firebase swift2 xcode7

我正在尝试在我的应用中创建用户个人资料页面,并且无法将快照数据分配给我创建的标签。

数据肯定会被拉入,因为我可以看到它被打印在日志中。我想取一个特定的值并将其分配给视图中的文本标签。

import UIKit
import Alamofire
import Firebase

class UserProfileVC: UIViewController {

@IBAction func editProfileButton(sender: AnyObject) {
}
@IBOutlet weak var userBio: UILabel!

@IBOutlet weak var userWebSite: UITextField!

@IBOutlet weak var userNameFL: UILabel!

@IBOutlet weak var applied: UILabel!

@IBOutlet weak var skipped: UILabel!

@IBOutlet weak var matched: UILabel!

var users = [User]()
static var imageCache = NSCache()
var user: User!


override func viewDidLoad() {
    super.viewDidLoad()

  navigationController?.navigationBar.tintColor = UIColor.whiteColor()

    DataService.ds.CURRENT_USER_REF.observeEventType(.Value, withBlock: {snapshot in

        print(snapshot.value)

        self.users = []

        if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {

            for snap in snapshots {

                print("SNAP: \(snap)")

                if let userDict = snap.value as? Dictionary<String, AnyObject> {

                    let key = snap.key
                    let user = User(postKey: key, dictionary: userDict)
                    self.users.append(user)

                }
            }

        }



    })

有人可以告诉我如何从正在打印的快照中获取数据并将其分配给给定的标签吗?这是快照的打印输出:

{
provider = password;
userName = "Ryan Bilak ";
}
SNAP: Snap (provider) password
SNAP: Snap (userName) Ryan Bilak 

1 个答案:

答案 0 :(得分:0)

假设您想在将用户添加到用户数组后立即设置标签文字,您可以这样做:userNameFL.text = userDict["userName"]