天天看點

Xcode 11 Xib _UITextLayoutView 崩潰Xcode 11 Xib _UITextLayoutView 崩潰

Xcode 11 Xib 

_UITextLayoutView

 崩潰

崩潰資訊如下:

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

}
           

參考