xcode Swift:构建成功,一个空白的应用程序窗口并显示此消息:无法在(NSWindow)上设置(contentViewController)用户定义的检查属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35887017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:37:30  来源:igfitidea点击:

Swift: Build succeeds, a blank app window and this message appear: Failed to set (contentViewController) user defined inspected property on (NSWindow)

xcodeswiftmacos

提问by Adam ?tefunko

I tried to create a simple Complex Number Calculator using classes. My application has compiled successfully, but when I ran it, a blank window appeared instead of a window with all my buttons, labels etc. and I got this message in the output window:

我尝试使用类创建一个简单的复数计算器。我的应用程序已成功编译,但是当我运行它时,出现了一个空白窗口,而不是一个包含所有按钮、标签等的窗口,我在输出窗口中收到了以下消息:

2016-03-08 22:20:42.499 Complex Numbers[30404:2328250] Failed to set (contentViewController) user defined inspected property on (NSWindow): Cannot create BOOL from object <_NSControllerObjectProxy: 0x6000000022c0> of class _NSControllerObjectProxy

2016-03-08 22:20:42.499 复数 [30404:2328250] 无法在(NSWindow)上设置(contentViewController)用户定义的检查属性:无法从对象 <_NSControllerObjectProxy:0x6000000022c0c0> of class _NSControllerObjectProxy 创建 BOOL

This is my ViewController class code. It involves a complexNumber class, which I didn't submit here:

这是我的 ViewController 类代码。它涉及到一个 complexNumber 类,这里我没有提交:

class ViewController: NSViewController {

    @IBOutlet var Screen: NSView!
    var a = complexNumber();

    @IBOutlet var realValue: NSTextField!

    @IBOutlet var imaginaryValue: NSTextField!

    @IBOutlet var resultLabel: NSTextField!

    @IBAction func lengthResult(sender: AnyObject) {

        let r = NSString(string: realValue.stringValue).doubleValue;
        let i = NSString(string: imaginaryValue.stringValue).doubleValue;

        a = complexNumber(real: r, imaginary: i);
        resultLabel.stringValue = String(a.trigonometric());
    }

    @IBAction func trigonometryResult(sender: AnyObject) {
        let r = NSString(string: realValue.stringValue).doubleValue;
        let i = NSString(string: imaginaryValue.stringValue).doubleValue;

        a = complexNumber(real: r, imaginary: i);
        resultLabel.stringValue = String(a.length());  
    }

    @IBAction func operation(sender: AnyObject) {
        a = complexNumber(real: NSString(string: realValue.stringValue).doubleValue, imaginary: NSString(string: imaginaryValue.stringValue).doubleValue);
        realValue.stringValue = ""
        imaginaryValue.stringValue = "";

        let b = complexNumber(real: NSString(string: realValue.stringValue).doubleValue, imaginary: NSString(string: imaginaryValue.stringValue).doubleValue)

        switch sender.stringValue {
            case "+": a = a.sum(b)
            case "-": a = a.dif(b)
            case "x": a = a.mul(b)
            case ":": a = a.div(b)
            default: a = a.sum(complexNumber())
        }
    }

    @IBAction func displayResult(sender: AnyObject) {
        resultLabel.stringValue = String("\(a.real) + i*\(a.imaginary)");
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }   
}

I found a similar thread here, but I don't think it's what I was looking for.

我在这里找到了一个类似的线程,但我认为这不是我想要的。

Can you help me, please?

你能帮我吗?

回答by Mike97

For me was a timing issue I guess. All begins after I added an SFAuthorizationView some days ago, and I discovered that thanks to a bug report, where also was clear that this is happening on older OSes like Sierra, but it is fine, instead, in 10.13+. Moving some code from viewDidLoad() to viewDidAppear() the problem gone. Basically I'm just waiting to call any related method of the problematic view later the viewcontroller content view is declared as loaded. Clearly a an Apple problem fixed in new OSes. So after instantiate the nib/xib/storyboard involved I think anyone encounter problems like that should firstly show the view and then customise it. Just my testimony.

对我来说,我猜是时间问题。几天前我添加了一个 SFAuthorizationView 之后,一切都开始了,我发现多亏了一个错误报告,其中也很清楚这发生在像 Sierra 这样的旧操作系统上,但它很好,相反,在 10.13+ 中。将一些代码从 viewDidLoad() 移动到 viewDidAppear() 问题消失了。基本上,我只是等待稍后调用有问题的视图的任何相关方法,然后将 viewcontroller 内容视图声明为已加载。显然是新操作系统中修复的 Apple 问题。所以在实例化涉及的nib/xib/storyboard 之后,我认为任何人遇到这样的问题都应该首先显示视图,然后对其进行自定义。只是我的见证。

回答by Mike Glukhov

Another reason - when you setup wrong binding. Example of my error:

另一个原因 - 当您设置错误绑定时。我的错误示​​例:

Failed to set (contentViewController) user defined inspected property on (NSWindow): [<NSProgressIndicator 0x10111b890> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Enabled.

To solve this you need to delete the binding here: enter image description here

要解决此问题,您需要删除此处的绑定: 在此处输入图片说明

回答by Praestolatio

I had this problem and figured it out.

我遇到了这个问题并想通了。

In my view I had a user defined property (if you look at the top of your view where you have view controller and first responder you should see it's icon next to it).

在我看来,我有一个用户定义的属性(如果您查看视图顶部的视图控制器和第一响应者,您应该看到它旁边的图标)。

Simply delete it and run your application.

只需删除它并运行您的应用程序。

Hope this helps!

希望这可以帮助!

回答by possen

One thing that may help others, I saw the same message, it looked like the contentViewController was the problem, but it turned out it was another component in something I was writing was failing. It seems the window manager catches all exceptions, not just window exceptions, and prints this deceptive message. What worked for me is stepping through to find component is not loading.

一件可能对其他人有帮助的事情,我看到了同样的消息,看起来 contentViewController 是问题所在,但事实证明这是我正在编写的另一个组件失败了。似乎窗口管理器捕获所有异常,而不仅仅是窗口异常,并打印此欺骗性消息。对我有用的是逐步找到未加载的组件。

回答by kamyFC

This happens when there is an error or exception in ViewDidLoad. Ensure that error is cleared and your UI will load fine and u wont get this message.

当 ViewDidLoad 中出现错误或异常时会发生这种情况。确保错误已清除并且您的 UI 将正常加载并且您不会收到此消息。

回答by Adrian Sluyters

I you've created an app with a"storyboard" i.e. if there's a storyboard file with your views and windows in it, then there's one of two things missing:

我已经创建了一个带有“故事板”的应用程序,即如果有一个包含视图和窗口的故事板文件,则缺少以下两件事之一:

1) If theres a main window and a view that should be it's main view, then right click - drag from the window controller to the view that should be the main view.. When the popup happens, click on "content view" i.e. like follows:

1)如果有一个主窗口和一个应该是主视图的视图,然后右键单击 - 从窗口控制器拖动到应该是主视图的视图..弹出窗口时,单击“内容视图”,即如下:

Check out my video example

查看我的视频示例

If this fails, then I'll dig out plan two :)

如果这失败了,那么我将挖掘出计划二:)

How this helps!!

这有什么帮助!!

Ade.

阿德。