我所有的 UIAlertController 消息都变成了单行 [英] All of my UIAlertController messages became single line

查看:25
本文介绍了我所有的 UIAlertController 消息都变成了单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否是罪魁祸首,但我对这个项目所做的最大改变是几天前升级到 Swift 4.我知道我的 UIAlertController 消息在需要时显示多行,但今天我偶然意识到所有这些消息都变成了单行并且最后有省略号.因为我从 API 显示这些消息,所以我不能使用\n".代码很简单;

I am not sure if this is the culprit but the biggest change I did to this project was upgrading to Swift 4 a couple of days ago. I know that my UIAlertController messages were showing multiline when needed but today I realized by chance that all of them became single line and has ellipsis at the end. Since I show these messages from an API, I cannot use "\n". The code is simple enough;

let alert = UIAlertController(title: "Title", message: "Long message that must be shown as multiline", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
    alert.dismiss(animated: true, completion: nil)
}))
present(alert, animated: true, completion: nil)

我检查了一些其他相关问题,但没有一个对我有用.最近有人问这个问题,但没有得到答案,并发布了一个解决方法;

I checked some other related questions but none of them worked for me. This one was asked as the same problem recently but did not get an answer, and has a hacky workaround posted as a solution;

所有警报对话框消息和文本字段已更改为单行.请查看图片

任何关于检查内容的建议都非常感谢.

Any advice on what to check is really appreciated.

推荐答案

不知道为什么会被否决,但我在拔头发 3 天后发现了这个问题.我一直在使用的第 3 方 Pod 之一中有一个 UILabel 扩展.它的代码被标记为已锁定",所以我认为这就是它之前没有出现在搜索结果中的原因.我不得不从他们的存储库中下载所有 pod 的源代码并在里面搜索.它覆盖了默认 UILabel 的这些函数和属性,而不是创建自己的 UILabel 子类;

Do not know why the downvotes but I have found the issue after 3 days of pulling my hair out. There was a UILabel extension in one of the 3rd party Pods I have been using. Its code was marked as "Locked" so I think that's why it did not show up in the search results before. I had to download the source codes for all of the pods from their repositories and searched inside. It was overriding these functions and properties of the default UILabel, instead of creating its own UILabel subclass;

override open func draw(_ rect: CGRect) {}
override open var intrinsicContentSize: CGSize {}

由于 UIAlertViewController 使用 UILabel 来显示消息,我尝试注释掉这些行,我的问题就消失了.如果有人遇到同样的问题,请在您的代码和嵌入式库源代码中搜索 UILabel 扩展.

Since the UIAlertViewController uses UILabel to display the message, I have tried to comment out these lines and my issue went away. If anyone having the same issue, search for UILabel extensions in your code AND in your embedded libraries source codes.

这篇关于我所有的 UIAlertController 消息都变成了单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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