Xcode 11 Xib UITextView 崩溃

Xcode 11 Xib _UITextLayoutView 崩溃

Xcode升级11.2之后,xib中使用UITextView突然闪退
之后看到大神转的文章完美解决了问题,参考原文稍作了修改 https://blog.csdn.net/zzsatym/article/details/102919289

我的崩溃信息如下:

 *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UITextLayoutView because no class named _UITextLayoutView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)'
*** First throw call stack:
(0x1b4a0498c 0x1b472d0a4 0x1b48fa054 0x1b7fad6f8 0x1b7fada6c 0x1b7f49ec8 0x1b8e6d354 0x1b8e13f2c 0x1b8d09248 0x1046147e0 0x1046148a0 0x1b86bbc2c 0x1b7fad838 0x1b7f49ec8 0x1b86bfc7c 0x1b7fad838 0x1b7fada6c 0x1b7f49ec8 0x1b86bacc8 0x1b86bd8b8 0x1b8404b4c 0x1b84055d8 0x1b8405890 0x1b8405f94 0x1b8365804 0x1b8378de8 0x1b837a2ec 0x1b835e060 0x1b8e9d270 0x1bb3895f8 0x1bb38de28 0x1bb399894 0x1bb2e29f0 0x1bb30c890 0x1bb30d284 0x1b4981c48 0x1b497cb34 0x1b497d100 0x1b497c8bc 0x1be7e8328 0x1b8a126d4 0x10461cd10 0x1b4807460)
libc++abi.dylib: terminating with uncaught exception of type NSException
3个解决方案:
  1. UITextView使用纯代码可以有效避坑

  2. 下载其他版本Xcode(个人觉得没必要)

  3. 使用Runtime黑魔法
    创建 文件 UITextViewWorkaround 继承 NSObject

  • swift
import UIKit

@objcMembers
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!)
                }
            }
        }
}
  • OC .m

#import "UITextViewWorkaround.h"
#import  <objc/runtime.h>
 
@implementation UITextViewWorkaround
 
+ (void)executeWorkaround {
    if (@available(iOS 13.2, *)) {
    }
    else {
        const char *className = "_UITextLayoutView";
        Class cls = objc_getClass(className);
        if (cls == nil) {
            cls = objc_allocateClassPair([UIView class], className, 0);
            objc_registerClassPair(cls);
#if DEBUG
            printf("added %s dynamically\n", className);
#endif
        }
    }
}
 
@end

最后在AppDelegate调用即可

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        UITextViewWorkaround.executeWorkaround()
        return true
    }

感谢作者 https://blog.csdn.net/zzsatym/article/details/102919289

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 获取相册数据 http://kayosite.com/ios-development-and-detail-of-...
    0271fb6f797c阅读 1,606评论 0 1
  • 网站: http://ui4app.com/category 技术网站: http://www.bestsdk.c...
    LYPC_下里巴人阅读 1,072评论 0 1
  • 学习开发资料 自己搜索使用过的一些资料,仅供参考。 资源中心 - 微信开放平台:https://open.weix...
    猿王阅读 650评论 0 1
  • 今日总结 张海霞,体验塑形,感觉有点累,朋友已经办了卡,了解我们的卡价,并不急着办卡 尹彩霞 ,条件很一般但又想练...
    hollow_6b31阅读 124评论 0 0
  • 从今天起, 做一个蕙质兰心的女子, 一如初遇他时的模样,阳光下尽是温婉… 我乘飞机, 穿过岁月的蓝天白云, 跋涉五...
    天思静默阅读 524评论 4 7