View Controller Code

import UIKit import Firebase import FirebaseDatabase import FirebaseAuth import SideMenu class StocksViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{ @IBOutlet weak var tableview: UITableView! @IBOutlet weak var Activity: UIActivityIndicatorView! var db: FIRDatabaseReference! var roomsDictionary: NSDictionary? var needRandomizedRooms = true var roomKeysArray: NSMutableArray? = [] var mainSearchBar: UISearchBar? var mainNavigationTitleView: UIView? var mainRightBarButtonItem: UIBarButtonItem? var roomKeysArrayForTable:[String] = [] let seporator = " " var showOnly = "All" let showOnlyNetwork = "network" let showOnlyGenre = "genre" var stringForSampling = "" //MARK: - Lifecycle deinit { NotificationCenter.default.removeObserver(self) } override func viewDidLoad() { super.viewDidLoad() self.title = "Акции" self.Activity.startAnimating() self.db = FIRDatabase.database().reference() if FIRAuth.auth()?.currentUser != nil { self.getDatabase() FIRMessaging.messaging().subscribe(toTopic: "stock") FIRMessaging.messaging().subscribe(toTopic: "rooms") } } func getDatabase () { if AppData.sharedInstance.city == nil { } else { self.showExcusesAlert() } self.tableview.isHidden = true self.Activity.startAnimating() self.db.observeSingleEvent(of: .value, with: { (snapshot) in AppData.sharedInstance.needUpdateData = false AppData.sharedInstance.database = snapshot.value as? NSDictionary self.roomsDictionary = AppData.getRooms() self.Activity.stopAnimating() self.tableview.isHidden = false }) { (error) in print(error.localizedDescription) } } func showExcusesAlert() { if AppData.sharedInstance.showExcusesMessage == true { AppData.sharedInstance.showExcusesMessage = false //self.showAlert(message: "ΠŸΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ находится Π² стадии Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. ΠŸΡ€ΠΈΠ½ΠΎΡΠΈΠΌ извинСния Π·Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹Π΅ Π²Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ трудности ΠΏΡ€ΠΈ Ρ€Π°Π±ΠΎΡ‚Π΅ с ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { let vc = segue.destination as! RoomViewController let name = self.roomKeysArrayForTable[(self.tableview.indexPathForSelectedRow?.row)!] let dicti = self.roomsDictionary?[name] as! NSDictionary AppData.sharedInstance.roomName = name as String? vc.dataDictionary = dicti } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.roomKeysArrayForTable.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableview.dequeueReusableCell(withIdentifier: StocksTableViewCell.cellIdentifier1(), for: indexPath) as! StocksTableViewCell let name = self.roomKeysArrayForTable[indexPath.row] if self.roomsDictionary != nil { let dict1 = self.roomsDictionary?[name] as! NSDictionary cell.stocksViewController = self cell.configureCell1(name: name, dictionary: dict1) } return cell } } 

ViewControllerCell code

  import UIKit import FirebaseStorage import Firebase import SDWebImage class StocksTableViewCell: UITableViewCell { @IBOutlet weak var BorderView: UIView! @IBOutlet weak var ImageView: UIImageView! @IBOutlet weak var NameLabel: UILabel! @IBOutlet weak var Description: UILabel! var lastX: CGFloat = 16.0 var stepX: CGFloat = 0.0 var stocksViewController: StocksViewController! var nameRoom = "" static func cellIdentifier1 () -> String { return "StocksTableViewCell" } func configureCell1 (name: String, dictionary: NSDictionary) { self.nameRoom = name self.ImageView.image = UIImage(named: "placeholder_image") self.NameLabel.text = name.uppercased() UICustomizeHelper.roundCornersForView(view: self.BorderView) let storage = FIRStorage.storage() let storageRef = storage.reference() let reference = storageRef.child("stocks/"+name+".jpg") if let cacheUrl = AppData.sharedInstance.cacheRoomImagePathDictionary[name] { self.ImageView.sd_setImage(with: cacheUrl, placeholderImage: UIImage(named: "placeholder_image")) } else { reference.downloadURL { (url, error) in AppData.sharedInstance.cacheRoomImagePathDictionary[name] = url self.ImageView.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image")) } } (self.subviews as NSArray).enumerateObjects(options: NSEnumerationOptions.reverse) { (value, index, nil) in if self.subviews[index].tag == 545 { self.subviews[index].removeFromSuperview() } } } override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } } 
  • Not a good practice when UITableViewCell what is View works directly with Model. When it comes to MVC. - Vitaly
  • Where is your UITableView DataSource? - VAndrJ

1 answer 1

It is necessary to do debugging at runtime, breakpoints, checking the contents of variables, etc. The first to check what is there in self.roomsDictionary in the cellForRowAt indexPath method, if there is data, check it step by step, there is not so much there, if not - see why there is no data. The code is certainly not a fountain, but it should work in theory.