2015-08-27 129 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