NSUnknownKeyException - Xcode

时间:2016-08-26 20:31:16

标签: swift xcode

我的程序显示了这个问题。谁能告诉我什么是错的?

"2016-08-26 17:21:00.548 SegundaTentativa[2347:203583] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SegundaTentativa.ViewController 0x7f9749d188d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imQuadro.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010786dd85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000109611deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010786d9c9 -[NSException raise] + 9
    3   Foundation                          0x0000000107c3f19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x0000000108228d0c -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x000000010845f7fb -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x00000001077a7890 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x000000010845e1de -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x000000010822f8d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x0000000108230202 -[UIViewController loadView] + 178
    10  UIKit                               0x0000000108230560 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x0000000108230cd3 -[UIViewController view] + 27
    12  UIKit                               0x0000000108106fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
    13  UIKit                               0x000000010810769d -[UIWindow _setHidden:forced:] + 282
    14  UIKit                               0x0000000108119180 -[UIWindow makeKeyAndVisible] + 42
    15  UIKit                               0x000000010808ded9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    16  UIKit                               0x0000000108094568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
    17  UIKit                               0x0000000108091714 -[UIApplication workspaceDidEndTransaction:] + 188
    18  FrontBoardServices                  0x000000010b4a28c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    19  FrontBoardServices                  0x000000010b4a2741 -[FBSSerialQueue _performNext] + 178
    20  FrontBoardServices                  0x000000010b4a2aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    21  CoreFoundation                      0x0000000107793301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x000000010778922c __CFRunLoopDoSources0 + 556
    23  CoreFoundation                      0x00000001077886e3 __CFRunLoopRun + 867
    24  CoreFoundation                      0x00000001077880f8 CFRunLoopRunSpecific + 488
    25  UIKit                               0x0000000108090f21 -[UIApplication _run] + 402
    26  UIKit                               0x0000000108095f09 UIApplicationMain + 171
    27  SegundaTentativa                    0x0000000107688432 main + 114
    28  libdyld.dylib                       0x000000010a0d592d start + 1
    29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) "

的ViewController:

import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var lbTexto: UILabel!


    @IBOutlet weak var imgQuadro: UIImageView!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        lbTexto.text = "Que jogador de vôlei e?"
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func ChangeText(sender: AnyObject) {
        lbTexto.text = "Ricardinho"
    }


    @IBAction func HiddenQuadro(sender: AnyObject) {
        imgQuadro.hidden = true
    }


    /*@IBAction func TesteSimbora(sender: UIButton) {
        lbText.text = "Ricardinho"
    }

    @IBAction func EscondeQuadro(sender: UIButton) {
        imQuadro.hidden = true
    }*/

}

1 个答案:

答案 0 :(得分:2)

注意错误信息:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SegundaTentativa.ViewController 0x7f9749d188d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imQuadro.'

有些东西试图设置视图控制器的不存在的imQuadro属性,并且当从storyboard / xib加载控制器时,可能会发生堆栈跟踪提示出口。

您很可能在界面构建器中设置了错误的插座连接,如果您最初创建名为imQuadro的插座,然后仅在您的代码中手动将其修改为imgQuadro,则可能会发生错误。