美文网首页
iOS开发问题之:Xcode 11 Xib _UITextLay

iOS开发问题之:Xcode 11 Xib _UITextLay

作者: iOS发呆君 | 来源:发表于2020-12-10 14:24 被阅读0次

    Xcode 11 Xib _UITextLayoutView 崩溃

    作为一个开发者,有一个学习的氛围跟一个交流圈子特别重要,这是一个我的iOS交流群:196800191,加群密码:112233,不管你是小白还是大牛欢迎入驻 ,分享BAT,阿里面试题、面试经验,讨论技术, 大家一起交流学习成长!

    崩溃信息如下:

    *** 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)'
    

    解决方案:

    解决方案 一

    xib的部分视图改用硬核手写,以避坑。

    解决方案 二

    下载其他版本Xcode 传送门

    解决方案 三

    OC 黑魔法 Runtime。

    创建 文件 UITextViewWorkaround

    UITextViewWorkaround.h

    #import <Foundation/Foundation.h>
     
    @interface UITextViewWorkaround : NSObject
    + (void)executeWorkaround; 
    @end
    

    UITextViewWorkaround.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
    

    使用该静态方法

    #import "UITextViewWorkaround.h"
     
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
     
        [UITextViewWorkaround executeWorkaround];
        return yes;
    }
    

    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!)
                }
            }
        }
     
    }
    

    原文作者:VKOOY
    原文地址:https://blog.csdn.net/vkooy/article/details/103045880

    相关文章

      网友评论

          本文标题:iOS开发问题之:Xcode 11 Xib _UITextLay

          本文链接:https://www.haomeiwen.com/subject/qktrgktx.html