I have table view controller. My problem; The cell in my table view changes every time I enter the view controller. For example; There are 2 data (address-1 and address-2). The first row is address-1, the second row is address-2, when I re-enter the page, the cells change. How can I fix this problem. Thanks
import UIKit import Firebase import MapKit class DenemeTableViewController: UITableViewController { var ref: DatabaseReference! let user: User = Auth.auth().currentUser! var adresListesi = [Adresler]() var adres: Adresler! @IBOutlet var table: UITableView! override func viewDidLoad() { super.viewDidLoad() self.table.delegate = self self.table.dataSource = self Adresdefteri() } override func viewWillAppear(_ animated: Bool) { Adresdefteri() table.reloadData() } override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return adresListesi.count } //prob. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! DenemeTableViewCell let adresList = self.adresListesi[indexPath.row] cell.textLabel?.text = adresList.adresname return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath:IndexPath) { self.performSegue(withIdentifier: "DENEMEHARİTAGO", sender: indexPath.row) } func Adresdefteri() { ref = Database.database().reference() let adreslerim = ref adreslerim?.child("locations").child(user.emailWithoutSpecialCharacters).child("Adresler").observe( .value) { [self] (snapshot) in if let gelenVeributunu = snapshot.value as? [String:AnyObject]{ self.adresListesi.removeAll() for gelenSatirVerisi in gelenVeributunu { if let sozluk = gelenSatirVerisi.value as? NSDictionary { let key = gelenSatirVerisi.key let adresname = sozluk["adresname"] as? String ?? "" let latitude = sozluk["latitude"] as? Double ?? 0.0 let longitude = sozluk["longitude"] as? Double ?? 0.0 let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude) let adres = Adresler(adresname: adresname, latitude: latitude, longitude: longitude, adresid: key) self.adresListesi.append(adres) } } DispatchQueue.main.async { self.table.reloadData() } } }