Can I see the view hierarchy I have in my app whil

2019-01-27 04:17发布

I am debugging my iOS app and since I have a view push/dismiss calls, I want to make sure I don't have any views in my stack that I wouldn't expect. Is it possible to see this in the Xcode debugger?

3条回答
戒情不戒烟
2楼-- · 2019-01-27 04:52

You might find lldb comes to the rescue with 'recursiveDescription'. Simply set a breakpoint at the point where you are interested in the view hierarchy. If for example you want everything in the window you can type

(lldb) po [[[[UIApplication sharedApplication] windows] firstObject] recursiveDescription]

Alternatively, I often find that when debugging views I am mostly interested in the hierarchy for a particular view. In that instance you can hook straight in to the point in code you are curious about (for example the viewDidAppear: method) and type:

(lldb) po [self.view recursiveDescription]

Note: With Xcode 6 Apple have added realtime view debugging which you can access from the debug bar. Real Time View Debugging Xcode 6

查看更多
乱世女痞
3楼-- · 2019-01-27 05:01

There is also Reveal.app which provide much more features than Xcode realtime view debugging, has a nicer UI and integrates with AppCode.

查看更多
太酷不给撩
4楼-- · 2019-01-27 05:04

As all of your view controllers should be managed by the navigation controller, you should be able to do something like this:

NSArray * controllerArray = [[self navigationController] viewControllers];

for (UIViewController *controller in controllerArray){
   //Code here.. e.g. print their titles to see the array setup;
   NSLog(@"%@",controller.title);
}

Taken from here: How to iterate all the UIViewControllers on the app

查看更多
登录 后发表回答