I need to update a TableView every so often but doing so duplicates the cells

Related searches

I have a TableView that I am updating from time to time with a Timer so that the data of the TableView changes if necessary... What happens is that the data is updated but it is duplicated and it does not eliminate the data that it had previously, then it is generating a giant TableView.

How could I make them update but delete the data I had previously and leave only the new cells when the tableview is updated?

This is the code that I use in the timer to update the TV:

 @objc func updatetableview(){
    databaseRef.child("A_Usuarios").queryOrdered(byChild: "TipoUsuario").queryEqual(toValue: "Empresa").observe(.childAdded, with: { (snapshot) in
       let key = snapshot.key
       self.snap = (snapshot.value as? NSDictionary)!
       self.snap.setValue(key, forKey: "Uid")
       self.city = self.snap["Ciudad"] as? String ?? ""
       self.activo = self.snap["Activo"] as? String ?? ""
       if self.city == self.cdad && self.activo != "No" {
         if(key == self.loggedInUser?.uid){
            print("Same as logged in user, so don't show!")
         }
         else
         {
           self.usersArray.append(self.snap)
           //insert the rows
           self.tableview.insertRows(at: [IndexPath(row:self.usersArray.count-1,section:0)],  with: UITableView.RowAnimation.automatic)
          }
        }

      }) { (error) in
             print(error.localizedDescription)
         }

I hope you can help me, thank you very much!

You need to clear the array before doing another observe

@objc func updatetableview(){
 usersArray.removeAll()
 ....
}

BTW .observe(.childAdded is supposed to do the job , so you may need n't to do this

Solving duplicated / repeating cells in Table view, When a user tap on the cell, it means the task has been done and a For the tableview below, there's only ~15 visible cells on the screen at any given time, so the queue will Want to level up your iOS development skills? the Apple's documentation advice on not to update content in prepareForReuse. Yes you are right we need to use DISTINCT to remove duplicates and get only one record and this is what I am doing in the script. Please note, the table which I have used in the query does not have ID column which has different value for the same employee as indicated in your query.

The observer you have used returns all the values in the given path. This closure is called when a new child is added. But it gets all the available in that path, not only the newly added data.

This is why it is generating a giant TableView.

So you need to get the newly added data only using queryLimited(toLast: UInt)

databaseRef.child("A_Usuarios").queryOrdered(byChild: "TipoUsuario").queryEqual(toValue: "Empresa").queryLimited(toLast: 1).observe(.childAdded, with: { (snapshot) in

iOS: Animate TableView Updates. A better way to reload data, How about using a real-time database, so all the changes will be pushed Inside this method we need to reload the tableView and hide the refreshControl: We will have to find the difference between the cells as well, so it should the keys from this array, and remove the duplicates from the keys array: I suggest a few changes: 1. ScreenUpdating needs to be reset. 2. You need a DoEvents every so often or the StatusBar/Excel won't display updates if he's doing a large number of cells. Try If Right(x, 3) = "000" Then DoEvents (I think Right won't break on numbers with less than 3 digits, not sure) – puzzlepiece87 Sep 28 '16 at 15:22

In firebase, if you are observing same node 5 times then it will give you 5 events. So you are adding same record 5 times. So you need to check that you are already observing that node before observing. Following code creating a problem. Every time you call updateTableView. It is adding new observer and that why you get same records multiple times.

    databaseRef.child("A_Usuarios").queryOrdered(byChild: "TipoUsuario").queryEqual(toValue: "Empresa").observe(.childAdded, with: { (snapshot) in

reloadData(), Reloads the rows and sections of the table view. to construct the table, including cells, section headers and footers, index arrays, and so on. Doing so forces the table view to delete any uncommitted changes before reloading the data. To receive the latest developer news, visit and subscribe to our News and Updates. Every so often I export it again to get updated information. I keep adding notes to some customers and I want to be able to combine the old and new list, keeping the information and also keeping the UPDATED cells in the newer sheet (there are dates that update) The problem is when I do a remove duplicate it always keeps the older

UITableViewCell, Solving duplicated / repeating cells in Table view, Most of the duplicated You should update the data source that supports each row in the table to hold the text the Question: I have a UITableView which has a custom UITableViewCell that in It seems quite often it is a different problem for each person, and it doesn't� Tech support scams are an industry-wide issue where scammers trick you into paying for unnecessary technical support services. You can help protect yourself from scammers by verifying that the contact is a Microsoft Agent or Microsoft Employee and that the phone number is an official Microsoft global customer service number.

UITableview: The Essential Solution for Scrolling iOS Interfaces, In this step-by-step guide I will show you why a UITableView is often more Selecting cells, adding sections and using delegates Until all your users get the latest iOS update, you are stuck using UIKit in your apps. That So, my recommendation is: if you need scrolling, use a table view (or, eventually,� So you need to install or update a driver, but you often have a few choices in where you get it from. When you first plug in a device, Windows will often install its own generic version of the

I need ytd unique count based on team name and employe id for each month qwit different training name. Currently I am doing manually as taking pivot for each training based on unique criteria. So please help to get auto capture this number dof excwl daahdash report. Reply Delete

Comments
  • This crashes the application... This is the error: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out)."
  • Solved this using your code and adding tableview.reloadData()... Thanks.
  • this is temporary solution.
  • You need to keep track already added abservers in our case ie. "A_Usuarios/TipoUsuario/". Before registering any firebase observer you need to check you are listening already that node or not (using your logic). If not then only register new observer.