问题描述
此函数因运行时错误而失败:
This function fails with runtime error:
-[UIWindow viewForFirstBaselineLayout]: unrecognized selector sent to instance 0x7fb9dae257d0
有人遇到过吗?
UPD:
在模拟器 iOS 8.1/8.4 上失败.9.3 工作正常.
UPD:
Fails on simulator iOS 8.1/8.4. 9.3 works fine.
UPD2:UIWindow
创建如下:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = RootViewController.rootVC
window?.makeKeyAndVisible()
推荐答案
通过在我的项目中放置以下修复程序,我让视图调试器再次工作:
I got the view debugger working again by placing the following fix in my project:
#ifdef DEBUG
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@implementation UIView (FixViewDebugging)
+ (void)load
{
Method original = class_getInstanceMethod(self, @selector(viewForBaselineLayout));
class_addMethod(self, @selector(viewForFirstBaselineLayout), method_getImplementation(original), method_getTypeEncoding(original));
class_addMethod(self, @selector(viewForLastBaselineLayout), method_getImplementation(original), method_getTypeEncoding(original));
}
@end
#endif
当您的项目加载时,load
方法将执行,导致 viewForFirstBaselineLayout
和 viewForLastBaselineLayout
使用 viewForBaselineLayout
实现,如果它们当前没有实现,那么视图调试会得到它正在寻找的行为的 iOS8 风格.
When your project loads, the load
method will execute, causing viewForFirstBaselineLayout
and viewForLastBaselineLayout
to use the viewForBaselineLayout
implementation if they are not currently implemented, so view debugging gets iOS8 flavor the behavior it was looking for.
要将其添加到您自己的项目中,请在您的项目中创建一个新的空 Objective-C 文件并将内容粘贴到其中.您可以随意命名它.我称我的为UIView+FixViewDebugging".如果您在纯 Swift 项目中,则不需要需要创建桥接头.该文件将被编译到您的项目中,您无需引用它.
To add this to your own project, create a new empty Objective-C file in your project and paste the contents in. You can name it whatever you want. I call mine "UIView+FixViewDebugging". If you are in a pure Swift project you do not need to create a bridging header. The file will be compiled into your project and you don't need to reference it.
请注意,由于 #ifdef DEBUG
,这仅适用于调试版本.您可以删除它,但随后您可能会不小心将其编译到您的发布版本中(尽管它应该没有不良副作用).如果此方法不适用于这些行,请检查您的目标在 Build Settings > Apple LLVM - Preprocessing > Preprocessor Macros > Debug 中是否具有 DEBUG=1
.
Note this will only work for debug builds because of the #ifdef DEBUG
. You can remove it but then you may accidentally compile this into your release builds (though it should have no ill side effects). If this method isn't working with these lines, check that your target has DEBUG=1
in Build Settings > Apple LLVM - Preprocessing > Preprocessor Macros > Debug.
这篇关于Xcode 7.3 中的调试视图层次结构失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!