UINavigationController崩溃

时间:2014-07-30 19:50:57

标签: ios uinavigationcontroller

我花了一些时间来调试这个,但出于想法......也许我错过了一些东西,但这些是导航控制器发生的事情序列。当用户执行某些操作时,每个步骤都会发生:

  1. NavController top viewController是TopVC。
  2. [navController presentViewController:controller animated:animated completion:^(void){}];
  3. [navController dismissViewControllerAnimated:NO completion:nil];
  4. [navController pushViewController:VC1]
  5. [navigationController presentViewController:动画选择器:YES完成:^(void){}]
  6. [navController dismissViewControllerAnimated:YES completion:nil];
  7. [navController pushViewController:VC2 animated:YES];
  8. [self.navigationController popToViewController:TopVC animated:NO]; 然后转到上面的#1。
  9. 此流程第一次工作,但是当用户在步骤#2之后单击按钮时,#3调用会导致崩溃..启用Zombies后,它会以某种方式引用VC2!

    上面的一系列步骤正是我在代码中所做的。 crasher:

    2014-07-30 13:22:01.662 MyApp[41037:60b] *** -[MessageViewController respondsToSelector:]: message sent to deallocated instance 0x14d88940
    
    (lldb) bt
    
    * thread #1: tid = 0x29f33d, 0x02741411 CoreFoundation`___forwarding___ + 769, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
      * frame #0: 0x02741411 CoreFoundation`___forwarding___ + 769
        frame #1: 0x027410ee CoreFoundation`__forwarding_prep_0___ + 14
        frame #2: 0x013c3874 UIKit`-[UITextView canBecomeFirstResponder] + 117
        frame #3: 0x00e1e045 UIKit`-[UIResponder(Internal) _canBecomeFirstResponder] + 33
        frame #4: 0x00e1d017 UIKit`-[UIResponder becomeFirstResponder] + 242
        frame #5: 0x00d1860e UIKit`-[UIView(Hierarchy) becomeFirstResponder] + 114
        frame #6: 0x013c38e9 UIKit`-[UITextView becomeFirstResponder] + 79
        frame #7: 0x00d1865b UIKit`-[UIView(Hierarchy) deferredBecomeFirstResponder] + 67
        frame #8: 0x00d186ef UIKit`-[UIView(Hierarchy) _promoteSelfOrDescendantToFirstResponderIfNecessary] + 115
        frame #9: 0x00d189a9 UIKit`__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 216
        frame #10: 0x01daa68c Foundation`-[NSISEngine withBehaviors:performModifications:] + 107
        frame #11: 0x01c3a3c5 Foundation`-[NSISEngine withAutomaticOptimizationDisabled:] + 48
        frame #12: 0x00d18830 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 313
        frame #13: 0x00d23dd4 UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1875
        frame #14: 0x00d16dba UIKit`-[UIView(Hierarchy) addSubview:] + 56
        frame #15: 0x00db76f0 UIKit`-[UITransitionView transition:fromView:toView:removeFromView:] + 1205
        frame #16: 0x01087004 UIKit`__101-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:]_block_invoke_2 + 1472
        frame #17: 0x01085cdc UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 8737
        frame #18: 0x00de3bda UIKit`-[UIViewController _dismissViewControllerWithTransition:from:completion:] + 1647
        frame #19: 0x00de352e UIKit`-[UIViewController dismissViewControllerWithTransition:completion:] + 1281
        frame #20: 0x00de4729 UIKit`-[UIViewController dismissViewControllerAnimated:completion:] + 57
    

1 个答案:

答案 0 :(得分:0)

请发布一些代码,很难弄清楚导致崩溃的原因。

当你在第8步回到TopVC [self.navigationController popToViewController:TopVC animated:NO] - >当TopVC再次加载并执行第2步时,变量“controller”为空,因此导致崩溃。

我假设您在ViewDidLoad中实例化“controller”变量。如果是这种情况,请将实例化“controller”的代码移动到viewWillAppear方法并尝试。