Xcode调试——打印控制器层次结构和视图层次结构

  • Post author:
  • Post category:其他


在 LLDB 使用

po [[UIWindow keyWindow] recursiveDescription]

来检查层次结构。它可以以文本形式打印出

完整的视图层次结构



po [[[UIWindow keyWindow] rootViewController] _printHierarchy]

来检查视图控制器。这是一个苹果默默在 iOS 8 中为

UIViewController

添加的

私有辅助方法

使用方法:


用xcode启动app,然后点击xcode暂停运行按钮,然后在调试控制台输入下面语句:





<pre name="code" class="objc">(lldb) po [[[UIWindow keyWindow] rootViewController] _printHierarchy]
<HMViewController 0x7fa7d2df7fb0>, state: appeared, view: <UIView 0x7fa7d2f14920>

(lldb) po [[UIWindow keyWindow] recursiveDescription]
<UIWindow: 0x7fa7d2df9fc0; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x7fa7d2dfb000>; layer = <UIWindowLayer: 0x7fa7d2df63e0>>
   | <UIView: 0x7fa7d2f14920; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x7fa7d2f078c0>>
   |    | <_UILayoutGuide: 0x7fa7d2f14c90; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x7fa7d2f084a0>>
   |    | <_UILayoutGuide: 0x7fa7d2f15830; frame = (0 736; 0 0); hidden = YES; layer = <CALayer: 0x7fa7d2f11300>>

(lldb) bt
* thread #1: tid = 0xd2ee, 0x0000000106efe4de libsystem_kernel.dylib`mach_msg_trap + 10, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x0000000106efe4de libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x0000000106efd64f libsystem_kernel.dylib`mach_msg + 55
    frame #2: 0x000000010423f1d4 CoreFoundation`__CFRunLoopServiceMachPort + 212
    frame #3: 0x000000010423e62f CoreFoundation`__CFRunLoopRun + 1295
    frame #4: 0x000000010423de98 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #5: 0x00000001087caad2 GraphicsServices`GSEventRunModal + 161
    frame #6: 0x0000000104b6c676 UIKit`UIApplicationMain + 171
    frame #7: 0x00000001035455af 数据请求测试`main(argc=1, argv=0x00007fff5c6fb600) + 111 at main.m:14
    frame #8: 0x0000000106bcd92d libdyld.dylib`start + 1
(lldb) 




版权声明:本文为sunnyboy9原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。