How to populate tableView with data from childByAutoID
up vote
2
down vote
favorite
I have a FirebaseStructure like so:
"users" : { "OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Orders" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618
},
"Order" : {
"-LQYDWAKlzTrlTtO1Qiy" : "1 Tomato, 3 Orange, 2 Banana",
"-LQYspEfZaJIt-PaAvYa" : "1 Banana, 9 Apple, 2 Tomato",
"-LQsILjpNqKwLl9XBcQl" : "1 Apple"
}
}
}
I want to display the order history in a tableView
How can I populate the tableView
with the "Order"
without the childByAutoID
?
I have tried this, but it comes up empty:
class OrderHistoryTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var orderDateHistoryArray = [Double]()
var orderItemsHistoryArray = [String]()
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
getOrderHistory()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return orderItemsHistoryArray.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderHistoryCell") as! OrderHistoryTableViewCell
cell.orderHistoryItemsLabel.text = orderItemsHistoryArray[indexPath.row]
return cell
}
func getOrderHistory() {
//Get userinfo from database
let uid = Auth.auth().currentUser!.uid
let orderDateHistoryRef = Database.database().reference().child("users/(uid)/Orders/")
orderDateHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let orderItem = value?["Order"] as? String ?? ""
self.orderItemsHistoryArray += [orderItem]
print(snapshot)
print(orderItem)
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
}
swift firebase firebase-realtime-database
add a comment |
up vote
2
down vote
favorite
I have a FirebaseStructure like so:
"users" : { "OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Orders" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618
},
"Order" : {
"-LQYDWAKlzTrlTtO1Qiy" : "1 Tomato, 3 Orange, 2 Banana",
"-LQYspEfZaJIt-PaAvYa" : "1 Banana, 9 Apple, 2 Tomato",
"-LQsILjpNqKwLl9XBcQl" : "1 Apple"
}
}
}
I want to display the order history in a tableView
How can I populate the tableView
with the "Order"
without the childByAutoID
?
I have tried this, but it comes up empty:
class OrderHistoryTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var orderDateHistoryArray = [Double]()
var orderItemsHistoryArray = [String]()
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
getOrderHistory()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return orderItemsHistoryArray.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderHistoryCell") as! OrderHistoryTableViewCell
cell.orderHistoryItemsLabel.text = orderItemsHistoryArray[indexPath.row]
return cell
}
func getOrderHistory() {
//Get userinfo from database
let uid = Auth.auth().currentUser!.uid
let orderDateHistoryRef = Database.database().reference().child("users/(uid)/Orders/")
orderDateHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let orderItem = value?["Order"] as? String ?? ""
self.orderItemsHistoryArray += [orderItem]
print(snapshot)
print(orderItem)
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
}
swift firebase firebase-realtime-database
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a FirebaseStructure like so:
"users" : { "OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Orders" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618
},
"Order" : {
"-LQYDWAKlzTrlTtO1Qiy" : "1 Tomato, 3 Orange, 2 Banana",
"-LQYspEfZaJIt-PaAvYa" : "1 Banana, 9 Apple, 2 Tomato",
"-LQsILjpNqKwLl9XBcQl" : "1 Apple"
}
}
}
I want to display the order history in a tableView
How can I populate the tableView
with the "Order"
without the childByAutoID
?
I have tried this, but it comes up empty:
class OrderHistoryTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var orderDateHistoryArray = [Double]()
var orderItemsHistoryArray = [String]()
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
getOrderHistory()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return orderItemsHistoryArray.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderHistoryCell") as! OrderHistoryTableViewCell
cell.orderHistoryItemsLabel.text = orderItemsHistoryArray[indexPath.row]
return cell
}
func getOrderHistory() {
//Get userinfo from database
let uid = Auth.auth().currentUser!.uid
let orderDateHistoryRef = Database.database().reference().child("users/(uid)/Orders/")
orderDateHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let orderItem = value?["Order"] as? String ?? ""
self.orderItemsHistoryArray += [orderItem]
print(snapshot)
print(orderItem)
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
}
swift firebase firebase-realtime-database
I have a FirebaseStructure like so:
"users" : { "OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Orders" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618
},
"Order" : {
"-LQYDWAKlzTrlTtO1Qiy" : "1 Tomato, 3 Orange, 2 Banana",
"-LQYspEfZaJIt-PaAvYa" : "1 Banana, 9 Apple, 2 Tomato",
"-LQsILjpNqKwLl9XBcQl" : "1 Apple"
}
}
}
I want to display the order history in a tableView
How can I populate the tableView
with the "Order"
without the childByAutoID
?
I have tried this, but it comes up empty:
class OrderHistoryTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var orderDateHistoryArray = [Double]()
var orderItemsHistoryArray = [String]()
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
getOrderHistory()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return orderItemsHistoryArray.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderHistoryCell") as! OrderHistoryTableViewCell
cell.orderHistoryItemsLabel.text = orderItemsHistoryArray[indexPath.row]
return cell
}
func getOrderHistory() {
//Get userinfo from database
let uid = Auth.auth().currentUser!.uid
let orderDateHistoryRef = Database.database().reference().child("users/(uid)/Orders/")
orderDateHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let orderItem = value?["Order"] as? String ?? ""
self.orderItemsHistoryArray += [orderItem]
print(snapshot)
print(orderItem)
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
}
swift firebase firebase-realtime-database
swift firebase firebase-realtime-database
edited Nov 9 at 14:06
Frank van Puffelen
221k25362387
221k25362387
asked Nov 9 at 13:05
Neccer
646
646
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Order
is a Dictionary
not a String
if let orderItem = value?["Order"] as? [String:String] {
self.orderItemsHistoryArray += Array(orderItem.values)
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Order
is a Dictionary
not a String
if let orderItem = value?["Order"] as? [String:String] {
self.orderItemsHistoryArray += Array(orderItem.values)
}
add a comment |
up vote
1
down vote
accepted
Order
is a Dictionary
not a String
if let orderItem = value?["Order"] as? [String:String] {
self.orderItemsHistoryArray += Array(orderItem.values)
}
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Order
is a Dictionary
not a String
if let orderItem = value?["Order"] as? [String:String] {
self.orderItemsHistoryArray += Array(orderItem.values)
}
Order
is a Dictionary
not a String
if let orderItem = value?["Order"] as? [String:String] {
self.orderItemsHistoryArray += Array(orderItem.values)
}
answered Nov 9 at 13:12
Sh_Khan
34.9k51125
34.9k51125
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226285%2fhow-to-populate-tableview-with-data-from-childbyautoid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown