2015-08-27 373 views
2

我們有以下的問題,這是我如何重現它:iOS應用崩潰顯示,當鍵盤

  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的後衛,但虛擬機運行的內存,它並不能真正幫助

我出出主意!下面是跟蹤:

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() 

更新:我接觸蘋果的支持,以獲得幫助,因爲我一定要得到這個解決。我的想法是,我們正在做一些不好的內存管理,但Profiler不顯示殭屍。儘管在ADBEncondingStringToHex中有一個內存泄漏,但無法對該信息進行任何操作。也許完全不相關,也許不是......

+0

你有一個真正的iOS設備上的問題? – rmaddy

+0

是的,模擬器和實際設備上出現問題(iPad Mini和iPad上也有8.4)。在調試和發佈版本中。 – escarti

+0

在這裏的黑暗中拍攝,但我注意到你[tf becomeFirstResponder];在嘗試再次顯示鍵盤之前,您是否曾經辭去FirstResponder? – joels

回答

0

我認爲在viewDidLoad中調用[tf becomeFirstResponder]爲時尚早 - 在視圖是應用視圖層次結構的一部分之前。您應該將其稱爲viewWillAppear:viewDidAppear:

從文檔:

您可能會調用該方法做出響應者的物體,如視圖中的第一響應者。但是,如果它是視圖層次結構的一部分,則只應在該視圖上調用它。如果視圖的window屬性包含一個UIWindow對象,則它已安裝在視圖層次結構中;如果它返回nil,則該視圖將從任何層次結構中分離出來。

+0

將文本字段移動到不同的方法並將其添加爲層次結構中不同視圖的子視圖是我嘗試的第一件事情之一。無論在何時何地添加它都會發生。但我必須在viewControllers之間進行轉換。 – escarti

0

這種問題發生在我以前在iOS8.xx(儘管iOS7.xx沒有問題)。我通過在鍵盤彈出之前調用resignFirstResponder來解決它的問題,即成爲第一個響應者。所以我覺得任何事情之前,你應該調用下面的代碼,你TF 文本框的resignFirstResponder帶出鍵盤:

[tf resignFirstResponder]; 
+0

我會試一試,但調用becomeFirstResponder只是一種方法,可以讓自己不必點擊文本框來重現錯誤。無論如何明天會試一試。 – escarti

+0

@escarti這是否解決您的問題?請更新,所以我可能不得不提出另一種解決方案。 – SanitLee

+0

好吧,所以添加行[tf resignFirstResponer]會在崩潰和我的應用程序之間建立缺失的連接。看起來是什麼導致了崩潰是「resignFirstResponder」。可悲的是它不能解決問題。 – escarti