我正在运行一个应用程序,在AppDelegate类中,我收到错误线程1:信号SIGABRT在class AppDelegate: UIResponder, UIApplicationDelegate {
行上
The error message says 2014-12-29 18:10:03.687 Iphone App Learning[1160:144441] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Iphone_App_Learning.ViewController 0x7fcd58f0e270> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key TextField.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ad96f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c8dabb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ad96b79 -[NSException raise] + 9
3 Foundation 0x000000010b1ae7b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010ace0e80 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010b8e7c7d -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x000000010b746f98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x000000010b747588 -[UIViewController loadView] + 109
8 UIKit 0x000000010b7477f9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010b747c8e -[UIViewController view] + 27
10 UIKit 0x000000010b666ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x000000010b667041 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x000000010b67372c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010b61e061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
14 UIKit 0x000000010b620d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
15 UIKit 0x000000010b61fbf2 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x000000010e4672a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x000000010accc53c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010acc2285 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010acc2045 __CFRunLoopRun + 2389
20 CoreFoundation 0x000000010acc1486 CFRunLoopRunSpecific + 470
21 UIKit 0x000000010b61f669 -[UIApplication _run] + 413
22 UIKit 0x000000010b622420 UIApplicationMain + 1282
23 Iphone App Learning 0x000000010abb197e top_level_code + 78
24 Iphone App Learning 0x000000010abb19ba main + 42
25 libdyld.dylib 0x000000010d0b4145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
AppDelegate类看起来像这个`import UIKit
@UIApplicationMain class AppDelegate:UIResponder,UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
And the view controller looks like this
导入UIKit
类ViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 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.
}
} ` 我在模拟器中对此进行测试这可能不起作用,因为我没有iOS开发人员计划吗?
答案 0 :(得分:12)
看起来你与一个不再存在的插座之间存在挥之不去的联系。也许您删除了之前设置的textField?
在Xcode编辑器中按住Ctrl- /右键单击文件所有者,查找警告三角形。清除它(通过删除连接或重新连接到正确的插座),你可能会很好。
答案 1 :(得分:1)
这里可能有另一个原因:你做了一个Outlet,然后你改了名字或者用一个新名字添加另一个Outlet。
你可以这样检查:
单击您在Storyboard中放置的Label或Button元素,查看右侧栏,找到“显示连接检查器”,然后您就可以找到它的连接。
如果您在连接中犯了一些错误,它会在此处显示。
对我来说,我用一个Outlet创建了两个连接,这就是我不断收到错误的原因。我删除了一个错误的连接后,它编译成功。
答案 2 :(得分:0)
在Main.storyboard
我选择了我的文字字段,然后在最右边,我显示了Utilities
并选择了Show the Connections inspector
。在Referencing Outlets
部分,我选择了两个连接:
number-View Controller
和enterText-View Controller
。我只是选择了我x
上的enterText-View Controller
标记来删除它(因为在我的情况下我只想要一个数字选择)并解决了我的问题。