IOS应用程序 – 在同一时间多个赛格崩溃(去其他赛格,而一个是animation)

虽然一个segue(如perforrmsegue)的animation正在进行,如果其他segue发生(如果用户在那时按其他button),然后应用程序崩溃。

这里解决了 UINavigationController上pop和pushViewController的问题。

我们还可以使用同样的trik还有其他解决scheme。

崩溃后我得到下面的堆栈。 (在[NSException initWithCoder:]处执行)。

0 CoreFoundation 0x2f9fbf4b __exceptionPreprocess 1 libobjc.A.dylib 0x39d8b6af objc_exception_throw 2 CoreFoundation 0x2f9fbe8d -[NSException initWithCoder:] 3 UIKit 0x3217a48f -[UIView(Internal) _addSubview:positioned:relativeTo:] 4 UIKit 0x3217a417 -[UIView(Hierarchy) addSubview:] 5 UIKit 0x32342b71 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke 6 UIKit 0x321806e5 +[UIView(Animation) performWithoutAnimation:] 

如果这个豁免是由于任何其他原因,那么请提及,因为我不知道有关赛格。

这个解决scheme为我工作,我认为这是一般的做法,在程序中添加这个。

1)

首先将BOOL属性添加到您应用的AppDelegate的.h文件中

 @property (nonatomic) BOOL animatingViewControllerTransition; 

还要实现UINavigationControllerDelegate

 @interface Your_AppDelegate : UIResponder <UIApplicationDelegate, UINavigationControllerDelegate> 

将Your_AppDelegate设置为application:didFinishLaunchingWithOptions: UINavigationController委托application:didFinishLaunchingWithOptions:对您的appDelegate:

 ((UINavigationController *)self.window.rootViewController).delegate = self; 

2)

现在在appDelegate的.m文件中添加这个UINavigationControllerDelegate方法:

 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // Push/pop operation is allowed now. ((Your_AppDelegate *)[UIApplication sharedApplication].delegate).animatingViewControllerTransition = NO; } 

3)

最后,当你继续时,添加下面的代码

 - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender { // Don't allow to segue if already one of the view controllers is being animated BOOL viewControllerIsTransitioning = ((Your_AppDelegate *)[UIApplication sharedApplication].delegate).animatingViewControllerTransition; if (viewControllerIsTransitioning) { return NO; } return YES; } 

希望这将有助于一个有继续崩溃的问题。

我认为这是一个更简单的解决scheme:

 -(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender { return self == [self.navigationController.viewControllers lastObject] ? YES : NO; }