Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Swift 多个UITableViewCell,每个都具有UIProgressView,更新速度非常慢_Swift_Xcode_Performance_Uitableview_Uiprogressview - Fatal编程技术网

Swift 多个UITableViewCell,每个都具有UIProgressView,更新速度非常慢

Swift 多个UITableViewCell,每个都具有UIProgressView,更新速度非常慢,swift,xcode,performance,uitableview,uiprogressview,Swift,Xcode,Performance,Uitableview,Uiprogressview,我正在制作一个游戏,在UITableView中有10个UITableViewCells。10个UITableViewCells中的每一个都有一个UIProgressView以及许多其他视图。我每1/10秒更新一次UITableView,这非常慢,而且在旧设备上比较滞后。对于UX,我每1/10秒更新一次,给游戏一个平滑的进度视图 是否有一种方法可以只单独更新每个单元格中的进度视图,而不必调用将更新每个单元格中所有视图的tableView.reloadData() 代码示例: func tableV

我正在制作一个游戏,在
UITableView
中有10个
UITableViewCells
。10个
UITableViewCells
中的每一个都有一个
UIProgressView
以及许多其他视图。我每1/10秒更新一次
UITableView
,这非常慢,而且在旧设备上比较滞后。对于UX,我每1/10秒更新一次,给游戏一个平滑的进度视图

是否有一种方法可以只单独更新每个单元格中的进度视图,而不必调用将更新每个单元格中所有视图的
tableView.reloadData()

代码示例:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = self.tableView.dequeueReusableCell(withIdentifier: "businessCell", for: indexPath) as! BusinessCell

            cell.progress.progress = Float( businessArray[indexPath.row-1].getCurrentProgress() )

        //lots of other views are updated here

        return cell
    }
}
cell.progress.progress = Float( businessArray[indexPath.row-1].getCurrentProgress() )
cell.progress.progress = someVarLocalToViewControllerContainingTableView[indexPath.row]
我可以改一下这行吗:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = self.tableView.dequeueReusableCell(withIdentifier: "businessCell", for: indexPath) as! BusinessCell

            cell.progress.progress = Float( businessArray[indexPath.row-1].getCurrentProgress() )

        //lots of other views are updated here

        return cell
    }
}
cell.progress.progress = Float( businessArray[indexPath.row-1].getCurrentProgress() )
cell.progress.progress = someVarLocalToViewControllerContainingTableView[indexPath.row]
类似于这样的内容:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = self.tableView.dequeueReusableCell(withIdentifier: "businessCell", for: indexPath) as! BusinessCell

            cell.progress.progress = Float( businessArray[indexPath.row-1].getCurrentProgress() )

        //lots of other views are updated here

        return cell
    }
}
cell.progress.progress = Float( businessArray[indexPath.row-1].getCurrentProgress() )
cell.progress.progress = someVarLocalToViewControllerContainingTableView[indexPath.row]
当我更新这个本地变量时,它只会更新progressView还是什么? 我已经尝试了许多方法,但不知道如何做到这一点…

您可以使用:

self.tableView .reloadRows(at: <[IndexPath]>, with: <UITableViewRowAnimation>)
self.tableView.reloadRows(at:,with:)
而不是使用
tableView.reloadData()

请查看以下链接:

它可能对您的场景有所帮助。

您可以使用:

self.tableView .reloadRows(at: <[IndexPath]>, with: <UITableViewRowAnimation>)
self.tableView.reloadRows(at:,with:)
而不是使用
tableView.reloadData()

请查看以下链接:


它可能对您的场景有所帮助。

如果您需要更新特定单元格的进度,请调用此

func reloadProgress(at index: Int) {
     let indexPath = IndexPath(row: index, section: 0)

        if let cell = tableView.cellForRow(at: indexPath) as? BusinessCell {
            cell.progress.progress = Float( businessArray[index - 1].getCurrentProgress() )
        }
}
如果需要重新加载表中的所有条:

func reloadProgress() {
        for indexPath in tableView.indexPathsForVisibleRows ?? [] {

            if let cell = tableView.cellForRow(at: indexPath) as? BusinessCell {
                cell.progress.progress = Float( businessArray[indexPath.row - 1].getCurrentProgress() )
            }
        }
    }

如果需要更新特定单元格的进度,请调用此

func reloadProgress(at index: Int) {
     let indexPath = IndexPath(row: index, section: 0)

        if let cell = tableView.cellForRow(at: indexPath) as? BusinessCell {
            cell.progress.progress = Float( businessArray[index - 1].getCurrentProgress() )
        }
}
如果需要重新加载表中的所有条:

func reloadProgress() {
        for indexPath in tableView.indexPathsForVisibleRows ?? [] {

            if let cell = tableView.cellForRow(at: indexPath) as? BusinessCell {
                cell.progress.progress = Float( businessArray[indexPath.row - 1].getCurrentProgress() )
            }
        }
    }

我知道这一点,但是每次重新加载单元格时,每个单元格中都会更新大约12个其他视图。我试图只更新单元格中的ProgressView,而不是浪费cpu更新单元格中的其他每个视图。我知道这一点,但是每次重新加载单元格时,每个单元格中都会更新大约12个其他视图。我试图只更新单元格中的ProgressView,而不是浪费cpu更新单元格中的每个其他视图。当然,可以只更新每个tableview中的进度条框架-这应该是正确的解决方案。重新加载整个tableview就是为了这个,这是一场灾难。但是,您还应该向我们展示您用于更新进度的代码。当然,可以只更新每个表视图中的进度条框架,这应该是正确的解决方案。重新加载整个tableview就是为了这个,这是一场灾难。但是你也应该向我们展示你用来更新Progression的代码。这非常好用,从来没有想过这样做。谢谢!这工作非常完美,从来没有想过这样做,谢谢!