Macos应用程序以Xcode显示视图,但在Xcode外部启动时完全空白 [英] Macos app displays view in Xcode, but is totally blank when launched outside of Xcode

查看:181
本文介绍了Macos应用程序以Xcode显示视图,但在Xcode外部启动时完全空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型macOS应用程序,我正在使用MacOS 10.14.5上的Xcode 10.2.1中的情节提要/界面生成器来构建该应用程序(尽管我将部署目标设置为10.13,如果这很重要).

I'm working on a small macos app, which I'm building with storyboards/interface builder in Xcode 10.2.1 on MacOS 10.14.5 (though I've set a deployment target of 10.13, if that matters).

当我在Xcode中运行该应用程序时,即通过点击播放"按钮,该应用程序可以很好地加载并且可见并可以运行.

When I run the app within Xcode, i.e., by hitting the "play" button, it loads up just fine and is visible and operates.

但是,当我将其归档"到一个独立的可执行文件,然后尝试从硬盘驱动器运行该应用程序时,它会在空白屏幕上打开. (请参见下面的屏幕截图.)

However, when I "archive" it to a freestanding executable and then try to run the app from the hard drive, it opens up on a blank screen. (See screenshots below.)

我已经清理了构建文件夹.我还确保清除所有/所有构建警告和自动布局约束警告.

I've cleaned the build folder. I've also made sure to clear any/all build warnings and autolayout constraint warnings.

在这里,可以在xcode中完美运行:

Here it is, running perfectly fine within xcode:

在这里,当单独运行时显示nada:

And here it is, displaying nada when run on its own:

该应用程序不使用任何第三方库,不使用捆绑软件资产,并且仅具有一个ViewController-在这里完全没有花哨的事情.我正在做的唯一奇怪的UI事情是,在右下角有一个很小的Web视图,我将其用作黑客来加载基于js的Web内容(工作屏幕截图中神秘的白点)./p>

The app uses no third-party libraries, no bundle assets, and only has one ViewController---nothing fancy at all happening here. The only weird UI thing that I'm doing is that there's a very small webview in the bottom-right corner that I'm using as a hack to load js-based web content (the mysterious white dot in the working screenshot).

推荐答案

好吧,我自己弄明白了,所以对于google/如果其他人有这个问题:WKWebView中似乎有一个错误种类,将其添加到IB会杀死视图中的所有其他内容. (或者也许是有意的,而WKWebView需要它自己的独立视图?Dunno.)

Ok, I figured this one out myself, so for the purposes of google/if someone else has this problem: there seems to be a bug in WKWebView of some kind, adding it to IB kills everything else in the view. (Or maybe this is intended, and WKWebView requires it's own independent view? Dunno.)

解决方案是以编程方式创建它,而根本不要将其放在视图中.您仍然可以在后台加载Web内容,从页面抓取信息等,而无需将其作为视图的一部分.

The solution is to create it programmatically and never put it in the view at all. You can still load web content in the background, scrape information from pages, etc. without it ever being part of a view.

这篇关于Macos应用程序以Xcode显示视图,但在Xcode外部启动时完全空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆