以 NSException (lldb) 类型的未捕获异常终止
Posted
技术标签:
【中文标题】以 NSException (lldb) 类型的未捕获异常终止【英文标题】:terminating with uncaught exception of type NSException (lldb) 【发布时间】:2017-06-11 13:37:43 【问题描述】:我遇到了一个错误, 以 NSException 类型的未捕获异常终止 (lldb) 。 错误是 error
追溯是
2017-06-11 22:10:04.009 Kenshin_Swift[6073:541383] Unknown class PhotoController in Interface Builder file.
2017-06-11 22:10:04.120 Kenshin_Swift[6073:541383] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fe830f06900> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key PhotoSelect.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001068efd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010635821e objc_exception_throw + 48
2 CoreFoundation 0x00000001068efc99 -[NSException raise] + 9
3 Foundation 0x0000000105c919df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x0000000106eae293 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010712279e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001068949e0 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x0000000107121122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000106eb49c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000106eb52e7 -[UIViewController loadView] + 177
10 UIKit 0x0000000106eb561c -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x0000000106eb5e70 -[UIViewController view] + 27
12 UIKit 0x0000000106f144f3 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 483
13 UIKit 0x0000000106f13935 -[UITabBarController transitionFromViewController:toViewController:] + 59
14 UIKit 0x0000000106f0f7f6 -[UITabBarController _setSelectedViewController:] + 365
15 UIKit 0x0000000106f0f678 -[UITabBarController setSelectedViewController:] + 234
16 UIKit 0x0000000106dcd239 +[UIView(Animation) performWithoutAnimation:] + 90
17 UIKit 0x0000000106f09c14 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 354
18 UIKit 0x0000000106f0ad8e -[UITabBarController viewWillAppear:] + 206
19 UIKit 0x0000000106ebb96f -[UIViewController _setViewAppearState:isAnimating:] + 692
20 UIKit 0x0000000106ebc07f -[UIViewController __viewWillAppear:] + 147
21 UIKit 0x0000000106ebd873 -[UIViewController viewWillMoveToWindow:] + 507
22 UIKit 0x0000000106dc3a87 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 621
23 UIKit 0x0000000106dd485b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 451
24 UIKit 0x0000000106dc30d7 -[UIView(Hierarchy) addSubview:] + 838
25 UIKit 0x0000000106d7f7bf -[UIWindow addRootViewControllerViewIfPossible] + 849
26 UIKit 0x0000000106d7fc06 -[UIWindow _setHidden:forced:] + 293
27 UIKit 0x0000000106d93519 -[UIWindow makeKeyAndVisible] + 42
28 UIKit 0x0000000106d0bf8d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
29 UIKit 0x0000000106d120ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
30 UIKit 0x0000000106d0f26d -[UIApplication workspaceDidEndTransaction:] + 188
31 FrontBoardServices 0x000000010a55d6cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
32 FrontBoardServices 0x000000010a55d544 -[FBSSerialQueue _performNext] + 189
33 FrontBoardServices 0x000000010a55d8cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
34 CoreFoundation 0x0000000106894761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
35 CoreFoundation 0x000000010687998c __CFRunLoopDoSources0 + 556
36 CoreFoundation 0x0000000106878e76 __CFRunLoopRun + 918
37 CoreFoundation 0x0000000106878884 CFRunLoopRunSpecific + 420
38 UIKit 0x0000000106d0daea -[UIApplication _run] + 434
39 UIKit 0x0000000106d13c68 UIApplicationMain + 159
40 Kenshin_Swift 0x0000000105b9f07f main + 111
41 libdyld.dylib 0x0000000109dc368d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
PhotoController 是
import Foundation
import UIKit
class PhotoController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate
@IBOutlet weak var myImageView: UIImageView!
@IBAction func PhotoSelect(_ sender: Any)
@IBAction func PhotoSend(_ sender: Any)
let myPickerController = UIImagePickerController()
myPickerController.delegate = self;
myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(myPickerController, animated: true, completion: nil)
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
myImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true, completion: nil)
override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//myImageUploadRequest()
override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
出口是 outlet
我了解了为什么会出现此错误消息。它说当“Outlet”错误时,就会发生这个错误。但我不知道如何解决这个问题。我看到PhotoSelect&PhotoSend的outlet有!,但我不明白这是什么意思。我该怎么办?
【问题讨论】:
这个错误是在构建时发生,还是在您选择图像时发生?如果在构建中,请删除并重新连接 Interface Builder 中的 imageView 插座。 【参考方案1】:问题在于PhotoSelect
和PhotoSend
这两个出口。您可能不小心将它们创建为@IBOutlet
,删除它们并重新创建为@IBAction
。
看看他们旁边有一个!
。这意味着这些插座不再连接。所以当你运行你的应用程序时,你的故事板在你的视图控制器中找不到这些出口,所以它崩溃了。
您需要通过单击x
删除这些插座。
【讨论】:
以上是关于以 NSException (lldb) 类型的未捕获异常终止的主要内容,如果未能解决你的问题,请参考以下文章
libc++abi.dylib:以 NSException (lldb) 类型的未捕获异常终止 TabBarController->TableViews->ViewControllers
以 NSException 类型的未捕获异常终止 - Xcode
Swift:以 NSException 类型的未捕获异常终止
Swift 项目以 NSException 类型的未捕获异常终止