Pregunta

While animation of one segue(like perforrmsegue) is going, if other segue occures (if user press other button at that time) then application is crashing.

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

Can we use same trik for segue also or there is other solution.

I get the following stack after crash. (Exeption at [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 exeption is for any other reason then please mention that because I an not sure about the segue.

¿Fue útil?

Solución

This solution worked for me and I think it's general practice to add this in the program.

1)

First add BOOL property to your .h file of your app's appDelegate

@property (nonatomic) BOOL animatingViewControllerTransition;

Also implement the UINavigationControllerDelegate:

@interface Your_AppDelegate : UIResponder <UIApplicationDelegate, UINavigationControllerDelegate>

Set Your_AppDelegate as UINavigationController's delegate in application:didFinishLaunchingWithOptions: of your appDelegate:

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

2)

Now Add this UINavigationControllerDelegate method in .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 are segueing

- (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 will help to one having segue crash problem.

Otros consejos

I think this is a more simpler solution:

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    return self == [self.navigationController.viewControllers lastObject] ? YES : NO;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top