我遇到以下错误:
[UTK_Math_Recruiting.FirstViewController keyboardWillHide:]: unrecognized selector sent to instance 0x7f824140f230
2016-12-08 11:01:57.696 UTK Math Recruiting[5844:333433] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UTK_Math_Recruiting.FirstViewController keyboardWillHide:]: unrecognized selector sent to instance 0x7f824140f230'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e41634b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ae6b21e objc_exception_throw + 48
2 CoreFoundation 0x000000010e485f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010e39bc15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010e39b798 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x000000010e3b419c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6 CoreFoundation 0x000000010e3b409b _CFXRegistrationPost + 427
7 CoreFoundation 0x000000010e3b3e02 ___CFXNotificationPost_block_invoke + 50
8 CoreFoundation 0x000000010e376ea2 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
9 CoreFoundation 0x000000010e375f3b _CFXNotificationPost + 667
10 Foundation 0x000000010a9330ab -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
11 UIKit 0x000000010c672c4e -[UIInputWindowController postStartNotifications:withInfo:] + 378
12 UIKit 0x000000010c674eef __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.871 + 382
13 UIKit 0x000000010bcb3a6d +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 581
14 UIKit 0x000000010bcb3ee8 +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:] + 119
15 UIKit 0x000000010c67491c -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1627
16 UIKit 0x000000010c67ce59 __43-[UIInputWindowController setInputViewSet:]_block_invoke.1316 + 98
17 UIKit 0x000000010c67029a -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 46
18 UIKit 0x000000010c67c9e2 -[UIInputWindowController setInputViewSet:] + 1923
19 UIKit 0x000000010c673f30 -[UIInputWindowController performOperations:withAnimationStyle:] + 50
20 UIKit 0x000000010c2ea24f -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1432
21 UIKit 0x000000010be11041 -[UIResponder _finishResignFirstResponder] + 267
22 UIKit 0x000000010c70e4e6 -[UITextField _finishResignFirstResponder] + 49
23 UIKit 0x000000010be11103 -[UIResponder resignFirstResponder] + 140
24 UIKit 0x000000010c70e3b5 -[UITextField resignFirstResponder] + 136
25 UIKit 0x000000010bca7703 -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 167
26 UIKit 0x000000010bca7d82 __UIViewWillBeRemovedFromSuperview + 76
27 UIKit 0x000000010bca7b3e -[UIView(Hierarchy) removeFromSuperview] + 95
28 UIKit 0x000000010bd72a86 -[UITransitionView _didCompleteTransition:] + 874
29 UIKit 0x000000010bd740cb -[UITransitionView transition:fromView:toView:removeFromView:] + 3851
30 UIKit 0x000000010bd731a8 -[UITransitionView transition:fromView:toView:] + 63
31 UIKit 0x000000010bd72ee3 -[UITransitionView transition:toView:] + 153
32 UIKit 0x000000010bdf985d -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 1889
33 UIKit 0x000000010bdf8721 -[UITabBarController transitionFromViewController:toViewController:] + 59
34 UIKit 0x000000010bdf45e2 -[UITabBarController _setSelectedViewController:] + 365
35 UIKit 0x000000010bdf4464 -[UITabBarController setSelectedViewController:] + 234
36 UIKit 0x000000010bdf85ce -[UITabBarController _tabBarItemClicked:] + 369
37 UIKit 0x000000010bbfb5b8 -[UIApplication sendAction:to:from:forEvent:] + 83
38 UIKit 0x000000010c013c72 -[UITabBar _sendAction:withEvent:] + 579
39 UIKit 0x000000010bbfb5b8 -[UIApplication sendAction:to:from:forEvent:] + 83
40 UIKit 0x000000010bd80edd -[UIControl sendAction:to:forEvent:] + 67
41 UIKit 0x000000010bd811f6 -[UIControl _sendActionsForEvents:withEvent:] + 444
42 UIKit 0x000000010c0163fa -[UITabBar _buttonUp:] + 113
43 UIKit 0x000000010bbfb5b8 -[UIApplication sendAction:to:from:forEvent:] + 83
44 UIKit 0x000000010bd80edd -[UIControl sendAction:to:forEvent:] + 67
45 UIKit 0x000000010bd811f6 -[UIControl _sendActionsForEvents:withEvent:] + 444
46 UIKit 0x000000010bd800f2 -[UIControl touchesEnded:withEvent:] + 668
47 UIKit 0x000000010bc68ce1 -[UIWindow _sendTouchesForEvent:] + 2747
48 UIKit 0x000000010bc6a3cf -[UIWindow sendEvent:] + 4011
49 UIKit 0x000000010bc1763f -[UIApplication sendEvent:] + 371
50 UIKit 0x000000010c40971d __dispatchPreprocessedEventFromEventQueue + 3248
51 UIKit 0x000000010c4023c7 __handleEventQueue + 4879
52 CoreFoundation 0x000000010e3bb311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
53 CoreFoundation 0x000000010e3a059c __CFRunLoopDoSources0 + 556
54 CoreFoundation 0x000000010e39fa86 __CFRunLoopRun + 918
55 CoreFoundation 0x000000010e39f494 CFRunLoopRunSpecific + 420
56 GraphicsServices 0x0000000111c3da6f GSEventRunModal + 161
57 UIKit 0x000000010bbf9964 UIApplicationMain + 159
58 UTK Math Recruiting 0x000000010a7f635f main + 111
59 libdyld.dylib 0x000000010f34368d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
以下是我使用的代码:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self,
selector: Selector(("keyboardWillShow:")),
name: NSNotification.Name.UIKeyboardWillShow,
object: nil)
NotificationCenter.default.addObserver(self,
selector: Selector(("keyboardWillHide:")),
name: NSNotification.Name.UIKeyboardWillHide,
object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self)
}
func keyboardWillShow(note: NSNotification) {
if let keyboardSize = (note.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
var frame = tableView.frame
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(0.3)
frame.size.height -= keyboardSize.height
tableView.frame = frame
if activeTextField != nil {
let rect = tableView.convert((activeTextField?.bounds)!, from: activeTextField)
tableView.scrollRectToVisible(rect, animated: false)
}
UIView.commitAnimations()
}
}
func keyboardWillHide(note: NSNotification) {
if let keyboardSize = (note.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
var frame = tableView.frame
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(0.3)
frame.size.height += keyboardSize.height
tableView.frame = frame
UIView.commitAnimations()
}
}
当应用启动时,它会启动到FirstViewController
。 FirstViewController
可以显示必须从UITableViewCell's
加载的自定义SecondViewController
形式。加载表单后,我点击UITextField
,好像用信息填写它,应用程序崩溃并出现上述错误。我无法弄清楚这个错误,它似乎只是抛出keyboardWillHide
的错误。