xcode 错误:无法将出口从 ... 连接到(NSTextField):缺少 setter 或实例变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30922937/
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 07:20:22  来源:igfitidea点击:

Error: Failed to connect outlet from ... to (NSTextField): missing setter or instance variable

xcodeswiftnstextfield

提问by Dominic J?rmann

Why does this code:

为什么这段代码:

if Note1Math.stringValue == "" {         
        TxtFilled = 0

        }else{

        TxtFilled = 1

    }

give this error?:

给这个错误?:

2015-06-18 20:20:17.633 Office[41763:430750] Failed to connect (Note1) outlet from (Office.ViewController) to (NSTextField): missing setter or instance variable.
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

2015-06-18 20:20:17.633 Office[41763:430750] 无法将 (Note1) 插座从 (Office.ViewController) 连接到 (NSTextField):缺少 setter 或实例变量。
致命错误:在解开可选值 (lldb) 时意外发现 nil

回答by Ken Thomases

This part of the message:

这部分消息:

2015-06-18 20:20:17.633 Office[41763:430750] Failed to connect (Note1) outlet from (Office.ViewController) to (NSTextField): missing setter or instance variable.

2015-06-18 20:20:17.633 Office[41763:430750] 无法将 (Note1) 插座从 (Office.ViewController) 连接到 (NSTextField):缺少 setter 或实例变量。

does not come from that code. It comes from the loading of a NIB or storyboard. Presumably, you had named an outlet Note1at one time, connected it in the NIB or storyboard, and then renamed it to Note1Mathin the code without fixing the NIB/storyboard.

不是来自那个代码。它来自 NIB 或故事板的加载。据推测,您曾经命名了一个插座Note1,将它连接到 NIB 或故事板中,然后Note1Math在没有修复 NIB/故事板的情况下在代码中将其重命名为。

Then, later, when you accessed Note1Math, it was nil(because it was not connected in the NIB/storyboard). That caused the second message:

然后,稍后,当您访问 时Note1Math,它是nil(因为它未在 NIB/故事板中连接)。这导致了第二条消息:

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

致命错误:在解开可选值 (lldb) 时意外发现 nil

The solution is to go into the NIB or storyboard, disconnect the outlet with the old name, and reconnect the outlet.

解决方法是进入NIB或storyboard,断开旧名称的插座,重新连接插座。

回答by nachshon f

Try this...

尝试这个...

if the Note1Math is a textbox...

如果 Note1Math 是一个文本框...

if Note1Math.text == "" {

        TxtFilled = 0

        }
else{

        TxtFilled = 1


    }

If the Note1Math is just a string...

如果 Note1Math 只是一个字符串...

  if Note1Math == "" {

            TxtFilled = 0

            }
    else{

            TxtFilled = 1


        }