多行 UILabel 无法在自动 UITableViewCell 上正确显示

wyu*_*wyu 0 iphone uitableview uilabel ios swift

编辑:我认为这可能与 iOS 8.3 有关。这不会发生在模拟器上,我的测试人员都没有遇到问题,但我的 8.3 开发手机确实有问题。关于如何解决它的任何想法?

edit2:我在这里找到了答案/sf/answers/2569777661/。我已经在下面回答了这个问题,并会在 2 天内接受,但我想这在技术上是重复的?

我有一个UITableViewrowHeight 设置为UITableViewAutomaticDimension

每个单元格包含多个标签,其中一个可以是多行。有时,单元格显示正确,标签占用多行。其他时候,单元格大小正确,但标签只占一行,在其他行应该消失的地方留下一个很大的空白空间。

tableview 由NSFetchedResultsController.

图片显示我的意思(要清楚“预期”不是渲染,它是应用程序有时工作的实际屏幕截图) 在此处输入图片说明

我尝试过的事情+想法

页面上有一个刷新操作,我试过了tableView.reloadData()tableView.setNeedsLayout()两者似乎都没有帮助

我注意到创建通知时我是否在 tableView 上,它显示正确。如果我强制退出应用程序(或从 XCode 再次运行应用程序)并且从获取结果中初始化单元格,那么它们会被错误地显示。

该应用程序也在运行testflight,在大约 5 名测试人员中,我们没有任何人报告过该问题。

编辑回答评论

设置标签 cellForRowAtIndexpath 的代码

let cell = tableView.dequeueReusableCellWithIdentifier(StoredNotificationViewController.snTableViewCellReuseIdentifier, forIndexPath: indexPath) as! StoredNotificationTableViewCell
configureCell(cell, atIndexPath: indexPath)
Run Code Online (Sandbox Code Playgroud)

配置单元

    let storedNotification = snFetchedResultsController.objectAtIndexPath(indexPath) as? StoredNotification
    cell.setData(storedNotification)
Run Code Online (Sandbox Code Playgroud)

cell.setData

    messageLabel.text = notification.message
Run Code Online (Sandbox Code Playgroud)

wyu*_*wyu 5

答案在这里/sf/answers/2569777661/

基本上,您添加cell.updateConstraintsIfNeeded()到 tableView(_:cellForRowAtIndexPath:) 方法的末尾