每当键入文本时,应用程序崩溃,无法识别的选择器发送到实例

每当我尝试在文本字段上写时,我都会使用我的应用程序崩溃这个奇怪的错误。

-[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x108e3eaf0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x108e3eaf0' 

我搜索了这个问题,但我真的不明白为什么会这样? 任何人都可以帮助我吗?

这是完整的错误..

  -[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x10450caf0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x10450caf0' *** First throw call stack: ( 0 CoreFoundation 0x00000001042e7e65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000103d60deb objc_exception_throw + 48 2 CoreFoundation 0x00000001042f048d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010423d90a ___forwarding___ + 970 4 CoreFoundation 0x000000010423d4b8 _CF_forwarding_prep_0 + 120 5 CoreFoundation 0x00000001042d3f23 -[NSTaggedPointerString compare:options:range:locale:] + 243 6 Foundation 0x00000001034d6e37 -[NSString compare:options:range:] + 29 7 UIKit 0x000000010497ee6f -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 303 8 UIKit 0x00000001048a33fd -[UIResponder _keyCommandForEvent:target:] + 364 9 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 10 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 11 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 12 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 13 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 14 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 15 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 16 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 17 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 18 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 19 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 20 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 21 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 22 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 23 UIKit 0x00000001048a35b2 -[UIResponder _keyCommandForEvent:target:] + 801 24 UIKit 0x00000001046b51aa -[UIApplication handleKeyHIDEvent:] + 397 25 UIKit 0x000000010468e838 _UIApplicationHandleEventQueue + 5469 26 CoreFoundation 0x0000000104213a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 27 CoreFoundation 0x000000010420995c __CFRunLoopDoSources0 + 556 28 CoreFoundation 0x0000000104208e13 __CFRunLoopRun + 867 29 CoreFoundation 0x0000000104208828 CFRunLoopRunSpecific + 488 30 GraphicsServices 0x0000000108449ad2 GSEventRunModal + 161 31 UIKit 0x0000000104694610 UIApplicationMain + 171 32 Parents-Baby Link 0x0000000102241dfd main + 109 33 libdyld.dylib 0x00000001066f292d start + 1 34 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 

好的,有一个解决方案可能适合你,请尝试将文本字段放在初始viewController中,并检查应用程序崩溃,如果应用程序没有崩溃键入你试试这个:

由于某种原因,我使用的标签栏控制器导致了问题。 只需删除控制器,然后转到编辑器>嵌入>标签栏控制器并重新添加视图修复它。 参考

在另一个问题可以是在Textfield中传递的数据不是有效格式可能是Null或者具有除string之外的无效格式

如果在键入文本字段时触发,我会检查是否有某种目标附加到文本字段,例如

 someButton.addTarget(self, action: #selector(self.someFunction()), forControlEvents: UIControlEvents.ValueChanged) 

有许多UIControlEvent可以触发。 但是,如果没有示例代码,我只能猜测。