将长字符串设置为UILabel冻结我的应用程序,但未检测到错误

问题描述 投票:0回答:1

((我使用https://www.charactercountonline.com来计数我的字符串,那么我的字符串是2253个字符)我想将UILabel设置为长字符串,但是我的应用不断冻结,而在xcode中没有错误登录。

我尝试用较短的字符串设置UILabel,成功了!我在设置UILabel时曾尝试使用DispatchQueue,但它也保持冻结,而没有显示错误日志。

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
           contentLabel.text = text  }

我该如何解决?这让我呆了几天。

编辑:我试图硬编码字符串的值。this is exactly the line where problem occured这正是发生问题的那一行

ios swift uikit uilabel swift4.2
1个回答
0
投票

尝试使用没有任何延迟DispatchQueue.main.async,即

DispatchQueue.main.async {[weak self] in
    self?.contentLabel.text = text
}

上面的代码对于任何长度text都可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.