Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从服务器更新阵列中的更改_Ios_Swift_Uitableview_Firebase - Fatal编程技术网

Ios 从服务器更新阵列中的更改

Ios 从服务器更新阵列中的更改,ios,swift,uitableview,firebase,Ios,Swift,Uitableview,Firebase,我有一个方法,可以从FireBase获取数据,将其保存在本地并加载到UITableView中。它工作得很好 现在,这个观察者(rootGenerals.observe())正在实时运行,并在每次服务器上的数据更改时进行更新 我的问题是,我不想在获得新数据后重新加载整个表(就像我现在所做的那样),我只想更新表中特定的已更改行,或者如果分数已更改,则替换行位置(IndexPath) 你知道怎么做吗?只是需要一些关于在这种情况下最好的处理方式的指导 rootGenerals.observe(.

我有一个方法,可以从FireBase获取数据,将其保存在本地并加载到UITableView中。它工作得很好

现在,这个观察者(rootGenerals.observe())正在实时运行,并在每次服务器上的数据更改时进行更新

我的问题是,我不想在获得新数据后重新加载整个表(就像我现在所做的那样),我只想更新表中特定的已更改行,或者如果分数已更改,则替换行位置(IndexPath)

你知道怎么做吗?只是需要一些关于在这种情况下最好的处理方式的指导

    rootGenerals.observe(.value, with: { snapshot in
        if !snapshot.exists() { return }

        let general = snapshot.value as! NSDictionary

        if let users : NSDictionary = general.object(forKey: "users") as? NSDictionary
        {
            if (self.usersFromDB?.count != 0) {
                //  Update table rows
                self.arrRecords = []
            }
            else {
                //  Create table from scratch
                self.usersFromDB = users

                for user : Any in users.allKeys {
                    let userDict : NSDictionary = users.object(forKey: user as! String) as! NSDictionary
                    let record : Record = Record()

                    record.displayName  = userDict.object(forKey: "name") as! String
                    record.time         = userDict.object(forKey: "time") as! Int
                    record.solvedLogos  = userDict.object(forKey: "logos_solved") as! Int
                    record.deviceId     = userDict.object(forKey: "device_id") as! String
                    record.raw          = userDict

                    self.arrRecords.append(record)
                }

                self.sortRecords()
            }
        }
    })

如果要更新特定索引路径,请使用

tableView.reloadRows(at: your_indexpath_array, with: your_Animation)
要在表中插入新行,请使用

 tableView.beginUpdates()
 tableView.insertRows(at: your_indexpath_array, with: your_Animation)
 tableView.endUpdates()

如果要更新特定索引路径,请使用

tableView.reloadRows(at: your_indexpath_array, with: your_Animation)
要在表中插入新行,请使用

 tableView.beginUpdates()
 tableView.insertRows(at: your_indexpath_array, with: your_Animation)
 tableView.endUpdates()
尝试使用以下方法:

rootGenerals.observe(.childAdded, with: { snapshot in
    //your code
})
因此,每次添加新的子用户时,它将只读取新数据

请尝试使用以下方法:

rootGenerals.observe(.childAdded, with: { snapshot in
    //your code
})

因此,每次添加新的子用户时,它将只读取新数据

,但如果该子用户已更新而未添加,该怎么办?在服务器中更新的应用程序与tableview中属于该应用程序的同一行之间进行同步的最佳方式是什么?当您刚刚运行应用程序时,它首先读取firebase中的每个子应用程序。如果在代码已经运行时添加了新的子级,则它将只读取新的子级。然后,您可以重新加载整个表或只在表中插入新行。对于子项的更新,也有类似的方法专门用于已更改的子项。希望我回答了所有的问题,在这里你可以从官方文档中找到所有的方法,但是如果孩子更新了而没有添加呢?在服务器中更新的应用程序与tableview中属于该应用程序的同一行之间进行同步的最佳方式是什么?当您刚刚运行应用程序时,它首先读取firebase中的每个子应用程序。如果在代码已经运行时添加了新的子级,则它将只读取新的子级。然后,您可以重新加载整个表或只在表中插入新行。对于子项的更新,也有类似的方法专门用于已更改的子项。希望我回答了所有的问题,在这里你可以从官方文件中找到所有的方法,谢谢,但这不是我要问的。。请阅读问题,我知道如何更新UITableView CellsHanks,但我不是这么问的。。请阅读问题,我知道如何更新UITableView单元格我认为您可以使用
。childChanged
事件类型来检测指定引用处的子项何时更新或更改我认为您可以使用
。childChanged
事件类型来检测指定引用处的子项何时更新或更改