【发布时间】:2018-01-01 06:12:11
【问题描述】:
使单元格出列需要 0.5-1.0 秒,这意味着我的 UITableView 需要超过 2-3 秒的时间来加载,即使它只有 4 行。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cellid = "NumberCell"
var isnumber = true
if indexPath.row == 0 {
cellid = "TextCell"
isnumber = false
}
NSLog("before dequeue \(indexPath)")
let cell = tableView.dequeueReusableCell(withIdentifier: cellid, for: indexPath) as! TextfieldTableViewCell
NSLog("dequeued")
// ...
return cell
}
直接在前后的 NSLog() 语句表明出队从 07.47 到 08.38。
2017-07-25 22:07:07.471898-0700 myapp[10209:4507471] 在 dequeue [0, 0] 之前
2017-07-25 22:07:07.679715-0700 myapp[10209:4507471] [MC] systemgroup.com.apple.configurationprofiles 路径的系统组容器是 /private/var/containers/Shared/SystemGroup/systemgroup。 com.apple.configurationprofiles
2017-07-25 22:07:07.683843-0700 myapp[10209:4507471] [MC] 从公共有效用户设置中读取。
2017-07-25 22:07:08.386960-0700 myapp[10209:4507471] 出队
单元格非常简单。它只有一个 UILabel 和一个 UITextField 并且 UITextField 有一个 Editing Changed 操作。就是这样。
到底是什么原因导致单元格出列需要这么长时间?是关于 System group 容器的其他两个系统 NSLog() 吗?
这使我的应用程序几乎无法使用,因为当我尝试使用此视图控制器时,应用程序似乎在设置 4 行时锁定了 2-4 秒。
我已经在 Objective-C 中制作了数百个 UITableViewController,但我从来没有遇到过这个问题。我错过了关于 Swift 3 的一些奇怪的东西吗?
【问题讨论】:
-
你在用
Nested ViewControllers吗? -
你用仪器中的时间分析器检查过代码吗?
-
转到 Xcode -> 产品 -> 方案 -> 编辑方案 在环境变量中,添加 OS_ACTIVITY_MODE 作为名称并禁用作为值 试试这个,让我知道
-
这似乎并不明显和必要。但是在 DispatchQueue.main.async 中编写你的代码,让我知道它是否能提高性能。将所有 dequeueReusable 代码放入其中。请让我知道它是否有效。
标签: ios swift uitableview swift3