ios应用程序 - 崩溃在多个segue在同一时间(去其他segue,而一个是动画) [英] ios App - crash on multiple segue at the same time (going to other segue while one is animating)

查看:761
本文介绍了ios应用程序 - 崩溃在多个segue在同一时间(去其他segue,而一个是动画)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个segue(如perforrmsegue)的动画正在进行时,如果其他segue发生(如果用户按当时的其他按钮),那么应用程序崩溃。



在UINavigationController上的pop和pushViewController的相同问题是 here



我们可以对segue使用相同的trik,还有其他解决方案。



崩溃。 (Exception 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:located:relativeTo:]
4 UIKit 0x3217a417 - [UIView(Hierarchy)addSubview:]
5 UIKit 0x32342b71 __53 - [_ UINavigationParallaxTransition animateTransition:] _ block_invoke
6 UIKit 0x321806e5 + [UIView(Animation)performWithoutAnimation:]

$ b

解决方案

如果这个exeption是因为任何其他原因,请提及,因为我不知道segue。



$ b

1)

这个解决方案适用于我,我认为通常的做法是将它添加到程序中。 $ b

首先向应用程序的appDelegate的.h文件添加 BOOL 属性

 code> @property(nonatomic)BOOL animatingViewControllerTransition; 

同时实现 UINavigationControllerDelegate

  @interface Your_AppDelegate:UIResponder< UIApplicationDelegate,UINavigationControllerDelegate> 

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

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

2)



现在添加此UINavigationControllerDelegate您的appDelegate的.m文件中的方法:

   - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *) viewController animated:(BOOL)animated 
{

//现在允许push / pop操作。
((Your_AppDelegate *)[UIApplication sharedApplication] .delegate).animatingViewControllerTransition = NO;
}

3)



最后添加以下代码

   - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:发件人
{
//如果已经有一个视图控制器正在动画,不允许segue
BOOL viewControllerIsTransitioning =((Your_AppDelegate *)[UIApplication sharedApplication] .delegate).animatingViewControllerTransition;
if(viewControllerIsTransitioning)
{
return NO;
}

return YES;
}

希望这将有助于有segue crash问题。


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.

解决方案

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.

这篇关于ios应用程序 - 崩溃在多个segue在同一时间(去其他segue,而一个是动画)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆