Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Firebase
- import FirebaseStorage
- class StoreViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var tableList: UITableView!
- var listProduct = [StoreModel]()
- var ref: DatabaseReference!
- let storage = Storage.storage()
- let storageRef = Storage.storage().reference()
- let userID = Auth.auth().currentUser!.uid
- var storeID = [String]()
- var shopID : String?
- override func viewDidLoad() {
- super.viewDidLoad()
- Database.database().reference().child("Users/Sellers").observe(DataEventType.value, with: { (snapshot) in
- if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
- print("SNAPSHOT: (snapshot)")
- for snap in snapshot {
- if let storeDict = snap.value as? Dictionary<String, AnyObject> {
- if storeDict["storename"] as? String != "" {
- let key = snap.key
- print(key)
- }
- }
- }
- }
- })
- let refList = Database.database().reference().child("Users/Sellers")
- refList.observe(DataEventType.value, with:{(snapshot) in
- if snapshot.childrenCount>0{
- self.listProduct.removeAll()
- for lists in snapshot.children.allObjects as! [DataSnapshot]{
- let productList = lists.childSnapshot(forPath: "user_info")
- let userList = productList.value as? [String: AnyObject]
- let listName = userList?["storename"]
- let list = StoreModel(name: listName as! String?)
- self.listProduct.append(list)
- }
- self.tableList.reloadData()
- }
- })
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return UITableView.automaticDimension
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return listProduct.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! StoreTableViewCell
- let list: StoreModel
- list = listProduct[indexPath.row]
- // let url = URL(string: list.product_image_url!)
- // let data = try? Data(contentsOf: url!)
- // if let imageData = data {
- // let image = UIImage(data: imageData)
- // cell.imgProduct.image = image
- // }else {
- // cell.imgProduct.image = UIImage(named: "avatar")
- // }
- cell.lblName.text = list.name
- return cell
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- self.performSegue(withIdentifier: "storetoproduct", sender: self)
- }
- }
- let refList = Database.database().reference().child("Users/Sellers")
- refList.observe(DataEventType.value, with:{(snapshot) in
- if snapshot.childrenCount>0{
- self.listProduct.removeAll()
- for user in snapshot.children.allObjects as! [DataSnapshot]{
- let productList = user.childSnapshot(forPath: "product_list")
- for product in productList.children.allObjects as! [DataSnapshot]{
- let userList = product.value as? [String: AnyObject]
- let listName = userList?["name"]
- let listDetail = userList?["details"]
- let listPrice = userList?["price"]
- let productImage = userList?["product_image_url"]
- let list = ListModel(name: listName as! String?, details: listDetail as! String?, price: listPrice as! String?, product_image_url: productImage as! String?)
- self.listProduct.append(list)
- }
- }
- self.tableList.reloadData()
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement