IOS swift 模拟器中UItextView中使用系统键盘输入汉字后立马崩溃,但英文没事,从别处复制粘贴的大段中文也没事,但一输入汉字又立马崩溃,跪求高手解救
Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSCFString substringFromIndex:]: Index 2 out of bounds; string length 1'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108864e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a8cadeb objc_exception_throw + 48
2 CoreFoundation 0x0000000108864d9d +[NSException raise:format:] + 205
3 Foundation 0x0000000108cf711d -[NSString substringFromIndex:] + 126
4 艾特便签 0x00000001066c60dd _TFCX13wtqIJFfHfgzph31CreateInformationViewController17textViewDidChangefS0_FCSo10UITextViewT_ + 509
5 艾特便签 0x00000001066c6a4a _TToFCX13wtqIJFfHfgzph31CreateInformationViewController17textViewDidChangefS0_FCSo10UITextViewT_ + 58
6 UIKit 0x0000000109d51847 -[UITextView textInputDidChange:] + 109
7 UIKit 0x0000000109d97cb7 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 138
8 UIKit 0x0000000109d9f751 -[UITextInputController setMarkedText:selectedRange:] + 744
9 UIKit 0x0000000109d505a4 -[UITextView setMarkedText:selectedRange:] + 75
10 UIKit 0x000000010994bc4a -[UIResponder(UITextInput_Internal) _setMarkedText:selectedRange:] + 91
11 UIKit 0x000000010964a2f8 -[UIKeyboardImpl unmarkText:] + 167
12 UIKit 0x000000010964cdf6 __59-[UIKeyboardImpl handleAcceptedCandidate:executionContext:]_block_invoke_2 + 39
13 UIKit 0x0000000109dba724 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
14 UIKit 0x0000000109dbaeb5 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 237
15 UIKit 0x0000000109654ba0 -[UIKeyboardImpl acceptCurrentCandidateForInput:] + 176
16 UIKit 0x0000000109a1c854 -[UIKeyboardCandidateBar collectionView:didSelectItemAtIndexPath:] + 298
17 UIKit 0x0000000109bf94a7 -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 701
18 UIKit 0x0000000109c1b049 -[UICollectionView touchesEnded:withEvent:] + 574
19 UIKit 0x00000001095b4ef7 forwardTouchMethod + 349
20 UIKit 0x00000001095b4fc0 -[UIResponder touchesEnded:withEvent:] + 49
21 UIKit 0x00000001095b4ef7 forwardTouchMethod + 349
22 UIKit 0x00000001095b4fc0 -[UIResponder touchesEnded:withEvent:] + 49
23 UIKit 0x0000000109881ede _UIGestureRecognizerUpdate + 10279
24 UIKit 0x0000000109417f8a -[UIWindow _sendGesturesForEvent:] + 1137
25 UIKit 0x00000001094191c0 -[UIWindow sendEvent:] + 849
26 UIKit 0x00000001093c7b66 -[UIApplication sendEvent:] + 263
27 UIKit 0x00000001093a1d97 _UIApplicationHandleEventQueue + 6844
28 CoreFoundation 0x0000000108790a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x000000010878695c __CFRunLoopDoSources0 + 556
30 CoreFoundation 0x0000000108785e13 __CFRunLoopRun + 867
31 CoreFoundation 0x0000000108785828 CFRunLoopRunSpecific + 488
32 GraphicsServices 0x000000010ccb1ad2 GSEventRunModal + 161
33 UIKit 0x00000001093a7610 UIApplicationMain + 171
34 艾特便签 0x00000001066bb5fd main + 109
35 libdyld.dylib 0x000000010b4c592d start + 1
36 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
PHP中文网2017-04-18 09:09:16
오류 메시지는 명백합니다. substringFromIndex 작업 액세스가 범위를 벗어났습니다. 프로그램의 이 부분에 해당하는 코드를 확인할 수 있습니다.
阿神2017-04-18 09:09:16
이 문제를 재현하지 않았으니 다행입니다. 아마도 코딩과 관련이 있을 것입니다. 콜백에 작성한 코드를 확인하세요. 게다가 시뮬레이터에만 문제가 있는 경우에는 실제 머신이 괜찮다면 걱정하지 마세요. 시뮬레이터가 실제 머신과 완전히 동일하지는 않습니다.