Ios App - crash when multiple transitions at the same time (transition to another segment while the animation)

While animation of one segue (for example, perforrmsegue) goes if another segue occurs (if the user presses another button at this time), the application is interrupted.

The same problem for pop and pushViewController in UINavigationController is solved here .

Is it possible to use the same trik for segue, as well as another solution.

After the failure, I get the next stack after the failure. (Exeption in [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:] 

If this is an exception for any other reason, then please indicate this because I am not sure about it.

+2
ios objective-c crash segue uistoryboardsegue
source share
2 answers

This solution worked for me, and I think it is common practice to add this to the program.

one)

First add the BOOL property to your .h appDelegate application file

 @property (nonatomic) BOOL animatingViewControllerTransition; 

Also use UINavigationControllerDelegate :

 @interface Your_AppDelegate : UIResponder <UIApplicationDelegate, UINavigationControllerDelegate> 

Set Your_AppDelegate as the UINavigationController delegate to application:didFinishLaunchingWithOptions: your app appDelegate:

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

2)

Now add this UINavigationControllerDelegate method to the .m file of your appDelegate:

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

3)

Finally, add the following code whenever you go

 - (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; } 

Hope this helps solve the crash issue.

+2
source share

I think this is a simpler solution:

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

All Articles