【问题标题】:UITableview Flickering in ios 11 while working correctly in iOS 10.2UITableview 在 iOS 11 中闪烁,同时在 iOS 10.2 中正常工作
【发布时间】:2018-09-11 19:50:15
【问题描述】:

当我单击特定单元格时,我正在尝试更新我的单元格大小。我的表格在 iOS 10.2 中得到完美更新,但是当我在 iOS 11 上运行我的代码时我的表格闪烁。我在 iOS 11 中也收到警告 -[UIApplication application state] must be used from main thread. 所以,我在调度队列中重新加载了我的表,但没有任何反应。我有多层 XIB,比如我有一个单元格,其中有一个表格,该表格正在注册另一个在点击时展开的单元格。 下面是我的代码示例,当高度扩展我的主表闪烁时。

func expandMessageTable(height : CGFloat,expendedRow:Int){

self.expandMessageHeight = height

self.msgExpRow = expendedRow

let row = cellMenuArr.index(of:"MessageXIB")

let path = IndexPath(row: row!, section: 0)
print(path)

homeTblView.reloadRows(at: [path], with: .fade)


}

【问题讨论】:

  • 当它实际上闪烁时。当你重新加载它?不要重新加载完整的表格,只需重新加载更新的单元格即可。
  • 当我在索引路径重新加载特定行时。
  • 你能告诉我们导致问题的代码吗?
  • 您需要提供重现闪烁的代码示例。对于另一个问题,您正在从后台线程调用 UIApplication.shared.applicationState 。使用 DispatchQueue.main.async { (...) } 在主线程上调度它
  • 我已经更新了我的查询,看看吧。我正在使用单元格 XIB。我在那个表中只有一个部分。

标签: ios swift ios11 ios10.2 ios11.3


【解决方案1】:

下面是我用来重新加载单元格的正常工作代码 -

DispatchQueue.main.async(execute: {
                            UIView.performWithoutAnimation {
                                self.tableView?.beginUpdates()
                                let contentOffset = self.tableView?.contentOffset
                                self.tableView?.reloadRows(at: [IndexPath(row: j, section: 0)], with: .automatic)
                                self.tableView?.setContentOffset(contentOffset!, animated: false)
                                self.tableView?.endUpdates()
                            }
                        })

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-06
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 2019-01-14
    • 2021-09-06
    • 2015-08-28
    相关资源
    最近更新 更多