Hello guys, I am currently working on an app for a valet company. So far so good until now. So for the project I have two table views. The first table view is the locations of the company. This displays all their locations. I have a second table view which works with the first one. If you click on a location from the first it loads in all the documents in that collection and puts them in the second table view. Now my problem is that when I switch locations and an update happens on the old location the second table view updates the information instead of ignoring it until the new location has a change.
I also have an authentication func to where before they can access any location they need to put in a pin and if it matches the location updates. Even if this is turned of the old location updates sill change the new location table view.
Code bellow
…
// func to select the individual row
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch tableView {
case SelectLocationTableView:
do {
if (allowed == false){ // postin data in table already but not reloading the page yet
Authenticate(title: "hi", message: "hi")
Location = postData[indexPath.row]
print("hi")
}
}
do { if (allowed == true){
allowed = false
Location = postData[indexPath.row]
CarsRequestedTableView.reloadData()
DisplayLocations()
}
}
case CarsRequestedTableView:
CarSelected = postCars[indexPath.row]
WorkWithCar()
default:
print(Error.self)
}
}
// function to pull the location based on the cell you click on
func DisplayLocations (){
let listener = db.collection("Requested").document(Location).collection("Requested").addSnapshotListener { querySnapshot, error in
guard (querySnapshot?.documents) != nil else {
print("Error fetching documents: \(error!)")
return
}
self.postCars.removeAll()
for document in querySnapshot!.documents {
let post = document.documentID
self.postCars.append(post)
self.CarsRequestedTableView.reloadData()
self.DisplayAlert(title: "NEW REQUEST!", message: "CHECK FOR NEW REQUEST!")
}
}
}
…