gpt4 book ai didi

ios - 此类对于键 不符合键值编码,其中 不在代码中(swift,Xcode 6)

转载 作者:搜寻专家 更新时间:2023-11-01 05:54:22 24 4
gpt4 key购买 nike

我输入了一个程序,其代码如下,来自一个教程,试图在多年后重新开始编码。

当我运行代码时,一切都会构建,但随后它会因上面的主题行错误而崩溃,命名一个没有出现在我的代码中任何地方的键(“helloText”)。完整的错误输出如下。

扭曲:有一次我将其中一个导出命名为“helloText”(现在命名为“nameTextField”)。

我查看了所有与我能找到的项目相关的文件,但找不到“helloText”。我还尝试了“清洁”菜单项。

感谢您的指导。

//
// ViewController.swift
// ConstructOStraws
//
// Created by Eric on 11/12/14.
// Copyright (c) 2014 Eric. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
setupUI()
}

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


@IBOutlet weak var helloLabel: UILabel!
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var helloButton: UIButton!

func setupUI(){

helloLabel.text = "Hello Swift!"
helloLabel.textColor = UIColor.redColor()
helloLabel.textAlignment = NSTextAlignment.Center

nameTextField.placeholder = "Enter your name"

helloButton.setTitle("Say Hell", forState: .Normal)

}


@IBAction func sayHelloAction(sender: AnyObject) {

let name = nameTextField.text

if name.isEmpty {

let alert = UIAlertController(title: "Error", message: "Please Enter a Name.", preferredStyle: UIAlertControllerStyle.Alert)

alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

self.presentViewController(alert, animated: true, completion: nil)
} else {

helloLabel.text = "Hello \(name)"
}
}

}

错误:

2014-11-12 15:23:10.521 ConstructOStraws[2048:67817] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ConstructOStraws.ViewController 0x7f82e866b420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key helloText.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001043b7f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105efbbb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001043b7b79 -[NSException raise] + 9
3 Foundation 0x00000001047cf7b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x0000000104301e80 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x0000000104f08c7d -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x0000000104d67f98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x0000000104d68588 -[UIViewController loadView] + 109
8 UIKit 0x0000000104d687f9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x0000000104d68c8e -[UIViewController view] + 27
10 UIKit 0x0000000104c87ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x0000000104c88041 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x0000000104c9472c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x0000000104c3f061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
14 UIKit 0x0000000104c41d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
15 UIKit 0x0000000104c40bf2 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x0000000107a9b2a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x00000001042ed53c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x00000001042e3285 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x00000001042e3045 __CFRunLoopRun + 2389
20 CoreFoundation 0x00000001042e2486 CFRunLoopRunSpecific + 470
21 UIKit 0x0000000104c40669 -[UIApplication _run] + 413
22 UIKit 0x0000000104c43420 UIApplicationMain + 1282
23 ConstructOStraws 0x00000001041d661e top_level_code + 78
24 ConstructOStraws 0x00000001041d665a main + 42
25 libdyld.dylib 0x00000001066d5145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

最佳答案

如果您重命名了 IBOutlets,那么您可能不会删除 Storyboard 中旧引用的引用,这些引用可能如下所示

Attached Screenshot

如屏幕所示,删除带有黄色感叹号三角形 的导出引用。您可以通过在 View Controller 的 Storyboard 中右键单击 First Responder 旁边的 view controller 对象来访问此屏幕。

关于ios - 此类对于键 <key> 不符合键值编码,其中 <key> 不在代码中(swift,Xcode 6),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26896069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com