我有一些UIButtons,当我加载ViewCOntroller时,应用程序崩溃,当我删除UI按钮时,应用程序正常工作并加载
这就是发生的事情
2016-01-17 16:27:51.151 HHKNBK[36147:32655609] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<HHKNBK.ViewController 0x7fed73052380> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key one.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f757e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001116bfdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010f757aa9 -[NSException raise] + 9
3 Foundation 0x000000010fd489bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x000000011032b320 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x0000000110559f41 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010f6984a0 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x0000000110558924 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000110331eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000110332816 -[UIViewController loadView] + 178
10 UIKit 0x0000000110332b74 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x00000001103332e7 -[UIViewController view] + 27
12 UIKit 0x00000001103858b0 -[UINavigationController preferredContentSize] + 194
13 UIKit 0x000000011030a0aa -[UIPresentationController preferredContentSizeDidChangeForChildContentContainer:] + 59
14 UIKit 0x0000000110306438 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 95
15 UIKit 0x00000001101a84a2 _runAfterCACommitDeferredBlocks + 317
16 UIKit 0x00000001101bbc01 _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
17 UIKit 0x00000001101c7af3 _afterCACommitHandler + 90
18 CoreFoundation 0x000000010f683367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
19 CoreFoundation 0x000000010f6832d7 __CFRunLoopDoObservers + 391
20 CoreFoundation 0x000000010f678f2b __CFRunLoopRun + 1147
21 CoreFoundation 0x000000010f678828 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000011486cad2 GSEventRunModal + 161
23 UIKit 0x000000011019c610 UIApplicationMain + 171
24 HHKNBK 0x000000010f10677d main + 109
25 libdyld.dylib 0x00000001121d192d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
这是代码
import UIKit
class ViewController: UIViewController {
@IBOutlet var live: mainbutton!
@IBOutlet var dt: mainbutton!
@IBOutlet var ms: mainbutton!
@IBOutlet var `as1`: mainbutton!
@IBOutlet var read: mainbutton!
@IBOutlet var pg: mainbutton!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = color125
live.setTitle("Live", forState: UIControlState.Normal)
dt.setTitle("Dhamma Talk", forState: UIControlState.Normal)
ms.setTitle("Mediations Stream", forState: UIControlState.Normal)
as1.setTitle("Adavanced And Special Streams", forState: UIControlState.Normal)
read.setTitle("Read", forState: UIControlState.Normal)
pg.setTitle("Program Guide", forState: UIControlState.Normal)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
App Delegate
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func grabStoryboard() -> UIStoryboard {
var storyboard = UIStoryboard()
let height = UIScreen.mainScreen().bounds.size.height
if height == 480 {
storyboard = UIStoryboard(name: "main3.5", bundle: nil)
} else if height == 568 {
storyboard = UIStoryboard(name: "main4", bundle: nil)
} else if height == 667 {
storyboard = UIStoryboard(name: "main6", bundle: nil)
} else if height == 736 {
storyboard = UIStoryboard(name: "main6plus", bundle: nil)
} else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
return storyboard
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().barTintColor = color125
let storyboard: UIStoryboard = self.grabStoryboard()
self.window?.rootViewController =
storyboard.instantiateInitialViewController()! as UIViewController
self.window?.makeKeyAndVisible()
return true
}
海关类别代码
override func awakeFromNib() {
self.backgroundColor = color125
self.layer.cornerRadius = 5
self.setTitleColor(UIColor.blackColor(), forState: .Normal)
}
答案 0 :(得分:1)
错误消息表明它们是名称“one”的插座的缺失链接(“对于密钥1”)。
2016-01-17 16:27:51.151 HHKNBK [36147:32655609] ***终止app到期 未捕获的异常'NSUnknownKeyException',原因: '[setValue:forUndefinedKey:]: 这个类不是关键值的密钥值编码。'
发生的事情是最初创建了“one”的插座(按住Ctrl键拖放),但代码中的变量名称已更改。
作为一个例子,我创建了一个名为“ one ”的商店:
@IBOutlet weak var one: UIButton! // Initially working
然后将一个重命名为已更改
@IBOutlet weak var changed: UIButton! // <- Now broken outlet
现在我收到相同的错误消息:
2016-01-17 18:56:14.059 InvalidOutlet [10158:5713712] ***终止 应用程序由于未捕获的异常'NSUnknownKeyException',原因: “[ setValue:forUndefinedKey:]:此类不是键值 符合编码的关键字。'
要解决此问题,请通过
删除无效的插座引用答案 1 :(得分:0)
我认为这条线是罪魁祸首 -
@IBOutlet var `as1`: mainbutton!
删除这些引号
@IBOutlet var as1: mainbutton!