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

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

为什么这个代码:

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

        }else{

        TxtFilled = 1

    }

出现这个错误?:

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)

试试这个...

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

if Note1Math.text == "" {

        TxtFilled = 0

        }
else{

        TxtFilled = 1


    }

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

  if Note1Math == "" {

            TxtFilled = 0

            }
    else{

            TxtFilled = 1


        }

这部分留言:

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.

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

然后,后来,当你访问Note1Math时,它是nil(因为它没有在NIB/storyboard中连接)。这导致了第二条消息:

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

解决方案是进入 NIB 或故事板,断开旧名称的插座,然后重新连接插座。