正确的UILabel大小在定义UITableViewCell(动画文本分配后) [英] UILabel incorrectly sized in UITableViewCell (Animation after assigning text)

查看:110
本文介绍了正确的UILabel大小在定义UITableViewCell(动画文本分配后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文本的UILabel 是显示,先用省略号出现在同一行,那么占据2号线它适合后闪烁。
注意,单元高度不发生变化。

The text in a UILabel is flickering after being displayed, first appearing with ellipsis on a single line, then occupying the 2 lines it fits in. Notice that the cell height doesn't change.

的UILabel包装

下面的问题是:结果
标签Друзъя,примитеучастиеинаполнитеКоробку! (朋友,参加并填写框!的)第一次出现的截断并认为过渡期错位为Друзъя,примитеучасти......

Here is the problem:
The label "Друзъя, примите участие и наполните Коробку!" (Friends, take part and fill the boxes!) first appears truncated and misaligned as "Друзъя, примите участи..." during the view transition.

这仅发生在与iOS 8.1 iPhone 4S。与标签(除了文本分配)所有的操作发生在故事板。

This happens only on iPhone 4s with iOS 8.1. All manipulation with Label (except text assigning) happens in the Storyboard.

是什么原因造成这种闪烁?

What is causing this flickering?

推荐答案

假设你正在改变的cellForRowAtIndexPath 测试,并进一步假设这并不适用于所有的字符串发生,只有一些具有一定的长度,那么这是一个iOS的错误。

Assuming you are changing the test in cellForRowAtIndexPath, and further assuming this does not happen with all strings, only some with certain length, then this is an iOS bug.

请参阅<了长时间的讨论href=\"http://stackoverflow.com/questions/14995573/dequeued-uitableviewcell-has-incorrect-layout-until-scroll-using-autolayout/35236138#35236138\">this堆栈溢出的UITableViewCell 帖子,以及可能的解决方法:

See lengthy discussion on this Stack Overflow UITableViewCell post, and a possible workaround:

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.setNeedsLayout()
    tableView.layoutIfNeeded()
    tableView.reloadData()
}


备注

1 我也注意到,使用一个小的值 estimatedRowHeight 20 ,这是不一样的最小单元为高,结合了一倍 reloadData()也有利。

1. I have also noticed that using a small value for estimatedRowHeight such as 20, which is not as tall as the smallest cell, in combination with the doubled reloadData() was also beneficial.

2 您将需要调用一个额外的 reloadData()之前 setNeedsLayout() tableView.editing

2. You will need to invoke an extra reloadData() prior setNeedsLayout() when changing the cell width, such as toggling tableView.editing

3 ,以一个标签摆弄一个强大的替代方案是使用的非编辑,非可选,没有资本化,使noScrolling,没有显示水平和放大器。垂直指示器,没有反弹的UITextView

3. A robust alternative to tinkering with a label is to use a non Editable, non Selectable, none Capitalization, noScrolling enabled, no Show Horizontal & Vertical Indicator, no Bounce UITextView.

要下载完整的项目中,你可以行使这个错误,并尝试使用的 X code 7 + 的iOS 9 + ,搜索的各种解决方法对于 35260912 中的雨燕食谱

To download the full project in which you can exercise this bug, and try out the various workarounds with Xcode 7+, iOS 9+, search for 35260912 in Swift Recipes.

这篇关于正确的UILabel大小在定义UITableViewCell(动画文本分配后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆