简体   繁体   English

如何在Interface Builder预览时查看打印调试? iOS / XCode

[英]How to see Print Debugging While Interface Builder Previews? IOS / XCode

When Interface Builder shows a preview of your ViewController, it must execute the code belonging to the views contained in that VC in order to draw them, right? 当Interface Builder显示ViewController的预览时,它必须执行属于该VC中包含的视图的代码才能进行绘制,对吗?

So... let's say you have some print debugging in your custom view... 所以...假设您在自定义视图中进行了一些打印调试...

print("draw() was executed")

... How can one see this output while Interace Builder is processing the preview? ...当Interace Builder处理预览时,如何看到此输出?

Thanks! 谢谢!

As far as I have seen, there is no way of printing to the debug console when Interface Builder is executing your code. 据我所知,Interface Builder执行代码时无法打印到调试控制台。 However, I did find it helpful to temporarily add messages to a label or textview instead. 但是,我确实发现将消息临时添加到标签textview很有帮助。

If necessary, you can do conditional code that only execute when Interface Builder is running (or not) like below. 如有必要,您可以执行仅在Interface Builder运行时(或不运行时)执行的条件代码,如下所示。 That way, you can show a small message view that is only visible at design time, and otherwise hidden. 这样,您可以显示一个小消息视图,该视图仅在设计时可见,否则隐藏。

#if TARGET_INTERFACE_BUILDER
  // IB only
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM