как я могу заполнить свой просмотр таблицы информацией из базы данных и хранилища с помощью firebase?Я бы показал что-то вроде этого Ячейка Это моя база данных База данных
import UIKit
import AVFoundation
import FirebaseDatabase
class HomeTableViewCell: UITableViewCell {
// MARK: - IBOutlets
@IBOutlet weak var name: UILabel!
@IBOutlet weak var imageViews: UIImageView!
@IBOutlet weak var ratingLabel: UILabel!
@IBOutlet weak var mapButton: UIButton!
@IBOutlet weak var backgroundCardView: UIView!
let orangeColor = UIColor(red: 255/255, green: 128/255, blue: 0/255, alpha: 1)
var bars : Bar?
override func awakeFromNib() {
super.awakeFromNib()
downloadImage()
backgroundCardView.backgroundColor = .white
backgroundCardView.layer.cornerRadius = 10
backgroundCardView.layer.masksToBounds = true
}
private func downloadImage() {
if let bar = bars {
Utility().getImage(withName: bar.imageName, completion: { (image) in
self.imageViews.image = image
})
}
}
}
class HomeTableViewController: UITableViewController, CAAnimationDelegate, UIViewControllerTransitioningDelegate {
// MARK: - IBOutlets
@IBOutlet weak var cartButton: UIButton!
@IBOutlet weak var helpButton: UIButton!
// MARK: - Variables
var bars : Bar?
var barList : [String]?
var dbRef = Database.database().reference()
var dbRoot = "Bar"
// MARK: - Load View
override func viewDidLoad() {
super.viewDidLoad()
SearchBar()
getBarList()
tableView.delegate = self
tableView.dataSource = self
self.tableView.rowHeight = 200
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
self.tableView.contentInset = UIEdgeInsetsMake(8, 0, 8, 0)
self.tableView.translatesAutoresizingMaskIntoConstraints = false
let imageView = UIImageView(image: UIImage(named: "logotext.png"))
imageView.widthAnchor.constraint(equalToConstant: 90).isActive = true
imageView.contentMode = .scaleAspectFit
self.navigationItem.titleView = imageView
cartButton.setImage(UIImage(named: "emptyCart.png"), for: .normal)
helpButton.setImage(UIImage(named: "help.png"), for: .normal)
}
private func getBarList() {
let query = (dbRef.queryOrdered(byChild: "name"))
query.observe(.value) { (snapshot) in
var bars : [Bar] = []
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
for snap in snapshot {
guard let valueDict = snap.value as? [String : Any] else {
return
}
let barcategories = Bar(withDictionary: valueDict)
bars.append(barcategories)
}
}
DispatchQueue.main.async {
self.bars = bars
self.tableView.reloadData() // aggiorno la tabella
}
}
}
func SearchBar() {
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = false
let searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
searchController.searchBar.placeholder = "Find a bar"
searchController.searchBar.tintColor = .gray
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let list = barList else {
return 0
}
return list.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! HomeTableViewCell
let bar : Bar!
let image = UIImage(named: barList![indexPath.row])
cell.contentView.layer.cornerRadius = 10
cell.contentView.layer.borderColor = UIColor.clear.cgColor
cell.contentView.layer.masksToBounds = false
cell.layer.shadowColor = UIColor.gray.cgColor
cell.layer.shadowOffset = CGSize(width: 0, height: 3)
cell.layer.shadowOpacity = 0.4
cell.layer.masksToBounds = false
cell.name.text = bar?.name
cell.imageViews.image = image
return cell
}
}