Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "Москва, Электрозаводская, 21"
- "Москва, Арбат, Староконюшенный переулок, дом 43"
- "Москва, улица 1-я Бухвостова, дом 12/11, корпус 53"
- class PhotoStudiosViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
- @IBOutlet weak var tableView: UITableView!
- var theStudios: [Studio] = []
- var studiosRef: DatabaseReference!
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(true)
- tableView.estimatedRowHeight = 475
- tableView.rowHeight = UITableViewAutomaticDimension
- loadDataFromFirebase()
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return theStudios.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! PhotoStudiosTableViewCell
- cell.addressLabel.text = theStudios[indexPath.row].studioAddress
- return cell
- }
- func loadDataFromFirebase() {
- studiosRef = Database.database().reference(withPath: "Addresses")
- let time = DispatchTime.now() + 0.5
- studiosRef.observe(.value, with: { (snapshot) in
- DispatchQueue.main.asyncAfter(deadline: time) {
- for imageSnap in snapshot.children {
- let studioObj = Studio(snapshot: imageSnap as! DataSnapshot)
- self.theStudios.append(studioObj)
- }
- self.tableView.reloadData()
- }
- })
- }
- class Studio {
- var ref: DatabaseReference!
- var studioAddress: String = ""
- init(snapshot: DataSnapshot) {
- ref = snapshot.ref
- studioName = snapshot.key
- let value = snapshot.value as! NSDictionary
- studioAddress = value["address"] as? String ?? "---"
- }
- }
Add Comment
Please, Sign In to add comment