簡體   English   中英

顯示鍵盤時iOS App崩潰

[英]iOS App crash when displaying Keyboard

我們有以下問題,這是我如何重現它:

  1. 我在rootviewcontroller和viewDidLoad中有一個文本字段:

     UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; tf.backgroundColor = [UIColor whiteColor]; tf.delegate = self; [self.view addSubview:tf]; [tf becomeFirstResponder]; 
  2. RootViewController有2個容器,一個用於側面菜單,一個用於實際的內容視圖。 它確實委托UITextFieldDelegate和UITextViewDelegate

  3. 如果啟動應用程序,則文本字段的行為正常
  4. 在像這樣瀏覽幾個視圖控制器之后:

     [destination.view setFrame:[[UIScreen mainScreen] applicationFrame]]; [self.currentVC willMoveToParentViewController:nil]; [self addChildViewController:destination]; [self transitionFromViewController:self.currentVC toViewController:destination duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished){ [self.currentVC removeFromParentViewController]; [destination didMoveToParentViewController:self]; self.currentVC = destination; self.currentSelection = selection; }]; 

每當我想使用“ Cmd + K”(仿真器)顯示鍵盤時,我都會得到EXC_BAD_ACCESS

同樣,崩潰的唯一方法是顯示系統鍵盤

  1. 啟用“僵屍”會使它更好一些,但最終會崩潰(僅當我打開鍵盤時)。
  2. 我嘗試了Malloc Guard,但VM內存不足,並沒有真正的幫助

我沒主意了! 這是跟蹤:

0   0x00c1d160 in CALayerGetSuperlayer ()
1   0x00fae832 in -[UIView(Hierarchy) superview] ()
2   0x00fa144a in -[UIView nextResponder] ()
3   0x010f39f1 in -[UIResponder(Internal) _responderWindow] ()
4   0x00fbbc89 in -[UIView(Internal) _firstResponder] ()
5   0x010f25c2 in -[UIResponder isFirstResponder] ()
6   0x01748243 in -[UITextView _keyboardDidShow:] ()
7   0x0222d079 in __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke ()
8   0x02dd8be4 in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
9   0x02cc511b in _CFXNotificationPost ()
10  0x0221c5d6 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
11  0x016fe4e5 in -[UIInputWindowController postEndNotifications:withInfo:] ()
12  0x01705660 in -[UIInputWindowController keyboardHeightChangeDone] ()
13  0x0117da40 in -[UIKeyboardImpl _resizeForKeyplaneSize:splitWidthsChanged:] ()
14  0x012ebf42 in __66-[UIKeyboardPredictionView setPredictionViewState:animate:notify:]_block_invoke ()
15  0x00fb7c06 in +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] ()
16  0x00fb7fc7 in +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] ()
17  0x012ebd31 in -[UIKeyboardPredictionView setPredictionViewState:animate:notify:] ()
18  0x012eb78a in -[UIKeyboardPredictionView setPredictionViewState:animate:] ()
19  0x01193b1a in -[UIKeyboardImpl showKeyboard] ()
20  0x01195fb0 in -[UIKeyboardImpl toggleSoftwareKeyboard] ()
21  0x01196020 in -[UIKeyboardImpl ejectKeyDown] ()
22  0x00f32920 in -[UIApplication _physicalButtonsBegan:withEvent:] ()
23  0x0269a7cd in -[NSObject performSelector:withObject:withObject:] ()
24  0x010f1c94 in forwardTouchMethod ()
25  0x010f4226 in -[UIResponder(Internal) _physicalButtonsBegan:withEvent:] ()
26  0x0269a7cd in -[NSObject performSelector:withObject:withObject:] ()
27  0x010f1c94 in forwardTouchMethod ()
28  0x010f4226 in -[UIResponder(Internal) _physicalButtonsBegan:withEvent:] ()
29  0x0269a7cd in -[NSObject performSelector:withObject:withObject:] ()
30  0x010f1c94 in forwardTouchMethod ()
31  0x010f4226 in -[UIResponder(Internal) _physicalButtonsBegan:withEvent:] ()
32  0x0269a7cd in -[NSObject performSelector:withObject:withObject:] ()
33  0x010f1c94 in forwardTouchMethod ()
34  0x010f4226 in -[UIResponder(Internal) _physicalButtonsBegan:withEvent:] ()
35  0x0176f4d3 in -[UITextField _physicalButtonsBegan:withEvent:] ()
36  0x00f8732a in -[UIWindow _sendButtonsForEvent:] ()
37  0x00f878d8 in -[UIWindow sendEvent:] ()
38  0x00f45681 in -[UIApplication sendEvent:] ()
39  0x00f55ab8 in _UIApplicationHandleEventFromQueueEvent ()
40  0x00f292e7 in _UIApplicationHandleEventQueue ()
41  0x02d3006f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
42  0x02d25b7d in __CFRunLoopDoSources0 ()
43  0x02d250d8 in __CFRunLoopRun ()
44  0x02d24a5b in CFRunLoopRunSpecific ()
45  0x02d2488b in CFRunLoopRunInMode ()
46  0x058352c9 in GSEventRunModal ()
47  0x05835106 in GSEventRun ()
48  0x00f2d0b6 in UIApplicationMain ()
49  0x001cd8ba in main at main.m:14
50  0x03b4cac9 in start ()

更新:由於必須解決此問題,因此我聯系了Apple支持以尋求幫助。 我的想法是我們正在執行一些錯誤的內存管理,但事件探查器未顯示任何僵屍。 雖然在ADBEncondingStringToHex中有一個內存泄漏,但無法對該信息執行任何操作。 也許完全無關,也許不...

我認為在viewDidLoad調用[tf becomeFirstResponder]還為時過早-在視圖成為應用程序視圖層次結構的一部分之前。 您應該在viewWillAppear:viewDidAppear:調用它。

從文檔:

您可以調用此方法使一個響應者對象(例如視圖)成為第一響應者。 但是,僅當它是視圖層次結構的一部分時,才應在該視圖上調用它。 如果視圖的window屬性包含一個UIWindow對象,則它已安裝在視圖層次結構中; 如果返回nil,則將視圖與任何層次結構分離。

這種問題是我之前在iOS8.xx中發生的(盡管iOS7.xx沒有問題)。 我通過調用becomeFirstResponder鍵盤之前跳出文本框的resignFirstResponder解決它。 因此,我認為您應該在產生鍵盤的任何內容之前調用以下代碼,將tf textField的resignFirstResponder簽名

 [tf resignFirstResponder];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM