import UIKit
import Firebase
class PendingVC: UIViewController,UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var myTableView: UITableView!
let ref = firebasehelper.firebaseURL()
var data = [[:]]
//MARK: vars
var address:AnyObject!
var postTitle:AnyObject!
override func viewDidLoad() {
super.viewDidLoad()
myTableView.dataSource = self
myTableView.delegate = self
//The example below work great I get the layout the way it should look, but i want to generate the dictionary from the firebase function below.
/*
self.data = [
[
"firstname": "sallie",
"lastname": "ammy"
],
[
"firstname": "jamie",
"lastname": "brown"
]
]
*/
It should look something like this and i want to past the data to the table. Im not sure if i should be looping. the way it is below bring the following error "fatal error: unexpectedly found nil while unwrapping an Optional value" the variables are not nil when i print them i get data back.
ref.childByAppendingPath("backend/posts").queryOrderedByChild("requestFrom").queryEqualToValue(ref.authData.uid).observeEventType(.ChildAdded, withBlock: {snapshot in
var firstname = snapshot.value["firstname"] as! String
var lastname = snapshot.value["lastname"] as! String
self.data = [
[
"firstname": firstname,
"lastname": lastname
]
]
print(self.data)
})
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! statusPrototypeCell
let object = data[indexPath.row]
cell.firstname.text = object["firstname"] as! String
cell.lastname.text = object["lastname"] as! String
return cell
}
override func viewWillAppear(animated: Bool) {
navigationController?.navigationBarHidden = false
navigationController?.navigationBar.barTintColor = UIColor(red:0.4, green:0.76, blue:0.93, alpha:1.0)
navigationController?.navigationBar.translucent = false
self.title = "Signup"
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
}
}