ios App - crash on multiple segue at the same time (going to other segue while one is animating)

蓝咒 提交于 2019-12-09 01:28:14

问题


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.


回答1:


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.




回答2:


I think this is a more simpler solution:

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


来源:https://stackoverflow.com/questions/22421845/ios-app-crash-on-multiple-segue-at-the-same-time-going-to-other-segue-while-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!