title: iOS7 - UITabBarController seletedIndex crash
body: <p>I am working on a <code>TabBar</code> based application. At some point I am doing:</p>
  
  <pre><code>if([[[appDelegate.tabBarController viewControllers] objectAtIndex:1] isKindOfClass:[UINavigationController class]]) {
      UINavigationController *navController = [[appDelegate.tabBarController viewControllers] objectAtIndex:1];
      [navController popToRootViewControllerAnimated:NO];
  }
  appDelegate.tabBarController.selectedIndex = 1; // CRASH HERE
  </code></pre>
  
  <p>On <code>iOS6</code> it is working fine but when I build the application with XCode5 / iOS7 then the application crash here <strong>randomly</strong>. Please help me guys.</p>
  
  <p>Thank you!</p>
  
  <p>Crash Logs:</p>
  
  <pre><code>* thread #1: tid = 0x4b606, 0x0557f811 CoreFoundation`___forwarding___ + 769, queue = 'com.apple.main-thread, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
  frame #0: 0x0557f811 CoreFoundation`___forwarding___ + 769
  frame #1: 0x0557f4ee CoreFoundation`_CF_forwarding_prep_0 + 14
  frame #2: 0x01128d6a UIKit`-[UISearchBar _didMoveFromWindow:toWindow:] + 168
  frame #3: 0x00eca847 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
  frame #4: 0x00eca847 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
  frame #5: 0x00eca847 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
  frame #6: 0x00ec2070 UIKit`__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 162
  frame #7: 0x00ec1ef8 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 260
  frame #8: 0x00ecd031 UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
  frame #9: 0x00ec0521 UIKit`-[UIView(Hierarchy) addSubview:] + 56
  frame #10: 0x00f5b1f8 UIKit`-[UITransitionView transition:fromView:toView:removeFromView:] + 1205
  frame #11: 0x00f5ad3b UIKit`-[UITransitionView transition:fromView:toView:] + 62
  frame #12: 0x00f5aadb UIKit`-[UITransitionView transition:toView:] + 123
  frame #13: 0x00fafe45 UIKit`-[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 1438
  frame #14: 0x00faf262 UIKit`-[UITabBarController transitionFromViewController:toViewController:] + 63
  frame #15: 0x00fab64b UIKit`-[UITabBarController _setSelectedViewController:] + 279
  frame #16: 0x00fab470 UIKit`-[UITabBarController setSelectedIndex:] + 261
  frame #17: 0x00014e6d TestApp`-[HomeViewController btn_TopRatedClicked:](self=0x0d813830, _cmd=0x0023559b, sender=0x0dbceb80) + 1533 at HomeViewController.m:707
  frame #18: 0x02311874 libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 77
  frame #19: 0x00e66c8c UIKit`-[UIApplication sendAction:to:from:forEvent:] + 108
  frame #20: 0x00e66c18 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
  frame #21: 0x00f5e6d9 UIKit`-[UIControl sendAction:to:forEvent:] + 66
  frame #22: 0x00f5ea9c UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 577
  frame #23: 0x00f5dd4b UIKit`-[UIControl touchesEnded:withEvent:] + 641
  frame #24: 0x00ea40cd UIKit`-[UIWindow _sendTouchesForEvent:] + 852
  frame #25: 0x00ea4d34 UIKit`-[UIWindow sendEvent:] + 1232
  frame #26: 0x00e78a36 UIKit`-[UIApplication sendEvent:] + 242
  frame #27: 0x00e62d9f UIKit`_UIApplicationHandleEventQueue + 11421
  frame #28: 0x055188af CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
  frame #29: 0x0551823b CoreFoundation`__CFRunLoopDoSources0 + 235
  frame #30: 0x0553530e CoreFoundation`__CFRunLoopRun + 910
  frame #31: 0x05534b33 CoreFoundation`CFRunLoopRunSpecific + 467
  frame #32: 0x0553494b CoreFoundation`CFRunLoopRunInMode + 123
  frame #33: 0x02b739d7 GraphicsServices`GSEventRunModal + 192
  frame #34: 0x02b737fe GraphicsServices`GSEventRun + 104
  frame #35: 0x00e6594b UIKit`UIApplicationMain + 1225
  frame #36: 0x0000213d TestApp`main(argc=1, argv=0xbfffed08) + 141 at main.m:16
  </code></pre>
  
  <p>At HomeViewController.m:707 I have found following statement:</p>
  
  <pre><code>appDelegate.tabBarController.selectedIndex = 1; // CRASH HERE
  </code></pre>