【问题标题】:uncaught exception of type NSException (connections seem fine) - Wenderlich tutorialNSException 类型的未捕获异常(连接似乎很好) - Wenderlich 教程
【发布时间】:2015-06-06 00:18:39
【问题描述】:

我是一名初学者,正在学习 Ray Wenderlich 的 Swift 教程,第 2 部分。

课程的最终代码(以及我收到错误的代码)在这里:http://cdn5.raywenderlich.com/wp-content/uploads/2014/06/TipCalculator-Demo4.zip

当我通过 Xcode 6.3.2 构建应用程序并在 iOS 模拟器 (iPhone 6) 上运行它时,我收到以下错误消息(抱歉格式不佳)。

我在 Google 和 StackOverflow 上都进行了搜索,似乎人们经常遇到类似的错误,但能够通过转到视图控制器、检查连接检查器并修复任何标记的连接(例如,所连接的对象不再存在)。

注意:我的 Connections Inspector 中没有任何标志 - 那里的一切看起来都很好,包括故事板中 resultsTextView 和 Text View 对象之间的连接(请参阅附图)

请告诉我如何解决这个问题 - 谢谢。

---------请参阅最右侧的连接检查器 - 看起来不错!-----------

http://i.imgur.com/X6eA05F.png

---------错误信息---------

2015-06-05 17:07:39.866 TipCalculator[4848:128801] * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不是键值编码- 符合关键 resultsTextView。 * 首先抛出调用栈:

(
0   CoreFoundation                      0x0000000100216c65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000101d81bb7 objc_exception_throw + 45
2   CoreFoundation                      0x00000001002168a9 -[NSException raise] + 9
3   Foundation                          0x0000000100634b53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4   CoreFoundation                      0x000000010015ed50 -[NSArray makeObjectsPerformSelector:] + 224
5   UIKit                               0x0000000100d8d52b -[UINib instantiateWithOwner:options:] + 1506
6   UIKit                               0x0000000100be5718 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7   UIKit                               0x0000000100be5d08 -[UIViewController loadView] + 109
8   UIKit                               0x0000000100be5f79 -[UIViewController loadViewIfRequired] + 75
9   UIKit                               0x0000000100c1601b -[UINavigationController _layoutViewController:] + 44
10  UIKit                               0x0000000100c16565 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 216
11  UIKit                               0x0000000100c16664 -[UINavigationController _startTransition:fromViewController:toViewController:] + 92
12  UIKit                               0x0000000100c17448 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523
13  UIKit                               0x0000000100c17f0e -[UINavigationController __viewWillLayoutSubviews] + 43
14  UIKit                               0x0000000100d62715 -[UILayoutContainerView layoutSubviews] + 202
15  UIKit                               0x0000000100b35a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
16  QuartzCore                          0x0000000104916ec2 -[CALayer layoutSublayers] + 146
17  QuartzCore                          0x000000010490b6d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
18  QuartzCore                          0x000000010490b546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
19  QuartzCore                          0x0000000104877886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
20  QuartzCore                          0x0000000104878a3a _ZN2CA11Transaction6commitEv + 462
21  UIKit                               0x0000000100ab3a2d -[UIApplication _reportMainSceneUpdateFinished:] + 44
22  UIKit                               0x0000000100ab46f1 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2648
23  UIKit                               0x0000000100ab30d5 -[UIApplication workspaceDidEndTransaction:] + 179
24  FrontBoardServices                  0x00000001038915e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
25  CoreFoundation                      0x000000010014a41c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
26  CoreFoundation                      0x0000000100140165 __CFRunLoopDoBlocks + 341
27  CoreFoundation                      0x000000010013f947 __CFRunLoopRun + 887
28  CoreFoundation                      0x000000010013f366 CFRunLoopRunSpecific + 470
29  UIKit                               0x0000000100ab2b42 -[UIApplication _run] + 413
30  UIKit                               0x0000000100ab5900 UIApplicationMain + 1282
31  TipCalculator                       0x000000010002c177 main + 135
32  libdyld.dylib                       0x00000001024d9145 start + 1
33  ???                                 0x0000000000000001 0x0 + 1
)

libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)

【问题讨论】:

  • 确保您的 resultsTextView 已连接到情节提要中的视图控制器。
  • 错误与resultsTextView有关。
  • @shim 谢谢,但我相信这些连接存在并且很好 - 刚刚添加了我的故事板视图的屏幕截图(包括最右边的连接检查器) - i.imgur.com/X6eA05F.png
  • 下载的代码对我来说很好用:O

标签: ios xcode swift debugging nsexception


【解决方案1】:

确保您正确地遵循这些步骤:

打开 Main.storyboard 并在 Document 中选择您的 View Controller 大纲。打开 Connections Inspector(第 6 个选项卡),您将看到 您创建的所有属性都列在 Outlets 部分中。 021_ConnectionsInspector 你会注意到右边有一个小圆圈 结果文本视图。按住 Control 从该按钮向下拖动到文本视图 在“计算”按钮下方,然后松开以连接您的 Swift 属性 到这个观点。

我相信您缺少在此步骤中创建的@IBOutlet

【讨论】:

  • 在 ViewController 我有“@IBOutlet var resultsTextView : UITextView!”这应该创造它。在所附屏幕截图最右侧的 Connections Inspector 中,连接似乎也很好:i.imgur.com/X6eA05F.png
  • 尝试清除此连接并构建项目并重新创建它,有时 xcode 会出现这样的有趣状态
猜你喜欢
  • 2015-11-17
  • 1970-01-01
  • 2018-12-04
  • 2016-03-25
  • 2017-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多