从Xcode 11.1升级到Xcode 11.2后,我的应用崩溃了:
***由于未捕获异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为_UITextLayoutView的类,因为没有找到名为_UITextLayoutView的类;类需要在源代码中定义或从库中链接(确保类是正确目标的一部分)'
为什么会这样?我怎样才能防止这种崩溃?
从Xcode 11.1升级到Xcode 11.2后,我的应用崩溃了:
***由于未捕获异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为_UITextLayoutView的类,因为没有找到名为_UITextLayoutView的类;类需要在源代码中定义或从库中链接(确保类是正确目标的一部分)'
为什么会这样?我怎样才能防止这种崩溃?
当前回答
改进@garafajon的回答。对我来说,这在大多数情况下都是可行的。
///Substitute class for _UITextLayoutView bug
class FixedTextView: UITextView {
required init?(coder: NSCoder) {
if #available(iOS 13.2, *) {
super.init(coder: coder)
}
else {
super.init(frame: .zero, textContainer: nil)
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.contentMode = .scaleToFill
self.isScrollEnabled = false // causes expanding height
// Auto Layout
self.translatesAutoresizingMaskIntoConstraints = false
self.font = UIFont(name: "HelveticaNeue", size: 18)
}
}
}
其他回答
作为一个“快速”修复,你可以直接从代码中添加UITextView,而不是通过IB,至少它对我有用。虽然从我的角度来看,最好回滚到以前的Xcode/等待新的。
我已经将khan的Obj-C解决方案改编为Swift:
import UIKit
@objc
class UITextViewWorkaround : NSObject {
static func executeWorkaround() {
if #available(iOS 13.2, *) {
} else {
let className = "_UITextLayoutView"
let theClass = objc_getClass(className)
if theClass == nil {
let classPair: AnyClass? = objc_allocateClassPair(UIView.self, className, 0)
objc_registerClassPair(classPair!)
}
}
}
}
在AppDelegate中的didFinishLaunchingWithOptions末尾调用它。
谢谢@Aftab !
11.2.1转基因种子解决了这个问题
(它可以用来发布到App Store)
登录https://developer.apple.com/download/。下载Xcode 11.2.1转基因种子
发布说明确认它修复了此错误:
你可以从苹果开发者网站下载最新的Xcode测试版(11.2.1 GM)。
这里是直接链接
我也有同样的问题,我只是把我的Xcode 11.2升级到11.2.1,它工作得很好。
升级后,我在iOs 13和iOs 12上测试了同样的功能,效果很好。