6

I am working on a medium-size iOS code base and am not the primary developer. I often find myself in a position where I run the app in the iOS simulator, see a view I know I would like to edit or use (e.g. a textview whose text I would like to get), but then don't have a good way of tracing said view back to a file in the code base. My question is, are there any good ways (either deterministically or heuristically) to "back trace" from a view one sees in the running instantiation of the app in the iOS simulator back to the code file/interface builder file that actually defines/contains said view?

For example, I see a textview in the simulator whose text I'd like to set differently, and I want a way to find the .xib/storyboard the textview is defined in and/or any IBOutlet's to it. I have tried using Reveal App, which seems to give some information about the app's overall view structure and view classes, but I haven't been able to reference this back to a code and/or interface builder file. Reveal App does show the memory address of views - perhaps there is a way to use this in combination with lldb to figure out which file the view came from?

Bryce Thomas
  • 9,405
  • 21
  • 69
  • 117
  • 1
    You might want to take a look at http://stackoverflow.com/questions/5150186/how-do-i-inspect-the-view-hierarchy-in-ios, specifically the accepted answer. – Jason Coco Aug 29 '13 at 01:09
  • I in one case resorted to writing special code that would search the view "tree" of a page for a certain X/Y location. It's not easy sometimes. – Hot Licks Aug 29 '13 at 01:09
  • Woah, Maybe I didn't get your question, seeing the other comments... – CaptJak Aug 29 '13 at 01:13
  • @JasonCoco that answers gets half way there. The problem isn't so much inspecting the view hierarchy as it is cross-referencing it back to code/IB files in the source code. E.g. I see a UILabel in the simulator and I want to change its text. How do I find which IB file/code file that UILabel is defined in? I know in some cases with static text etc you could just search for the string/use `grep`. I'm looking for a generalized way of cross-referencing live objects back to source code though... – Bryce Thomas Aug 29 '13 at 01:16
  • If you want to do this, you have to build it this way from the very beginning. You'd need to build some kind of useful identifiers and attach them as your accessibility identifiers in your app. Not only would they need to identify a specific view and its use, but give you a way to tell which files are presenting that view. – Jason Coco Aug 29 '13 at 01:23
  • Also, you should use some logical way to identify the strings for various UI elements and keep them in your localized interface strings files anyway. Then changing them is a matter of knowing that your on some specific view in the app, opening the strings file for that interface element and tweaking the text. – Jason Coco Aug 29 '13 at 01:25
  • @JasonCoco This may be the only solution, but I'm hoping not :(. Rog: Reveal App is mentioned in the question already. – Bryce Thomas Aug 29 '13 at 01:25
  • First thing you do, of course, is go into IB and look at the links. But a problem you have here is that often the IB view is poorly documented, so you have to spend half an hour adding names to all the pieces. – Hot Licks Aug 29 '13 at 03:27

2 Answers2

3

I know its a very old question. However, if you are still looking for an answer, you could break execution at any arbitrary point and use the lldb to print out some information.

Then, if, for example, your app, like most other apps, has a UINavigationController as a root view controller, then you could try and see whats the top view controller. If that's a TabView, then a little more digging.. u get the drift...

po [(UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController] topViewController]

This seems to work fairly well. Not too straightforward, but not a bad deal.

govi
  • 687
  • 9
  • 21
0

One way for you to do this would be to Ctrl+click on the outlet that you would like to edit (the text view or whatever) and see where the connections lead to. Or you could click on the item in need of edit and check the Connections Inspector in the right side and see what it is connected to.

That won't tell you exactly where it is, but it will give you the idea. Then you could just comb through the code in the area it pointed to, and see where it is referenced and whatnot.

Also if you do it this way, you can see what the outlet is called, which would then enable to search the code or the project for that outlet.

CaptJak
  • 3,542
  • 1
  • 25
  • 48
  • 1
    This answer addresses a related but different question. I'm more interested in the use case of *see something in simulator* -> *figure out where it's defined in source code*. – Bryce Thomas Aug 29 '13 at 01:18