ios <UINavigationController: 0xa98e050> 开始/结束外观转换的不平衡调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14412890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:55:41  来源:igfitidea点击:

Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0xa98e050>

iphoneiosobjective-cios6uinavigationcontroller

提问by KsK

While compiling the code i got

在编译我得到的代码时

"Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0xa98e050>"

“对“的开始/结束外观过渡的不平衡调用<UINavigationController: 0xa98e050>

warning.

警告。

Here is my code

这是我的代码

KVPasscodeViewController *passcodeController = [[KVPasscodeViewController alloc] init];
passcodeController.delegate = self;

UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:passcodeController];
[(UIViewController *)self.delegate presentModalViewController:passcodeNavigationController animated:YES];

回答by Mark Travis

I know this is an old question, but for the sake of those who run across this again, here is what I've found.

我知道这是一个老问题,但为了那些再次遇到这个问题的人,这是我发现的。

Firstly, The question does not state where the new viewControllerwas being called.
I suspect this was called from -(void)viewDidLoad

首先,这个问题没有说明 newviewController在哪里被调用。
我怀疑这是从-(void)viewDidLoad

Move the appropriate code to -(void)viewDidAppear:and the problem should go away.

将适当的代码移至-(void)viewDidAppear:,问题应该会消失。

This is because at -viewDidLoad, the view has loaded, but has not yet been presented and the animations and views have not completed.

这是因为 at -viewDidLoad,视图已加载,但尚未呈现,动画和视图尚未完成。

If your intent is to push a window, do it after the window has been presented and has painted.

如果您的意图是推动一个窗口,请在窗口呈现并绘制后执行。

If you ever find yourself using timers to control system behavior, ask yourself what you are doing wrong, or how you could do it more properly.

如果你发现自己使用定时器来控制系统行为,问问自己你做错了什么,或者你如何才能更正确地做到这一点。

回答by iPatel

I Found that this issue occurs if you trying to push new view controller while previous transaction (animation) in progress.

我发现如果您在上一个事务(动画)正在进行时尝试推送新的视图控制器,则会出现此问题。

Anyway, i think, it is presentModalViewControllerproblem, Set animated:NO, may be solve your problem

无论如何,我认为,这是presentModalViewController问题,Set animated:NO可能会解决您的问题

[(UIViewController *)self.delegate presentModalViewController:passcodeNavigationController animated:NO];

Other option is:

其他选项是:

Take NSTimerand call above code between may be 0.50 to 1second. This also helpful trick. so your pervious viewController has done its animation.

NSTimer和调用上面的代码之间可能是0.50 到 1秒。这也是有用的技巧。所以你之前的 viewController 已经完成了它的动画。

回答by Paula Vasconcelos Gueiros

This warning appears when you try to load a new viewController before a previously included one is done animating. If your intention is to do that, simply add your code to a dispatch_async(dispatch_get_main_queue()block:

当您尝试在先前包含的 viewController 完成动画之前加载新的 viewController 时,会出现此警告。如果您打算这样做,只需将您的代码添加到一个dispatch_async(dispatch_get_main_queue()块中:

dispatch_async(dispatch_get_main_queue(), ^(void){
        [(UIViewController *)self.delegate presentModalViewController:passcodeNavigationController animated:YES];
});

and the warning will go away.

并且警告将消失。

回答by Harald

a modern solution may be this:

一个现代的解决方案可能是这样的:

double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds *   NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self.window.rootViewController presentViewController:yourVC animated:YES completion:nil];
});

回答by 0xced

You did not provide much context, so I assume this error is happening at startup since you are presenting a passcode view controller.

您没有提供太多上下文,因此我假设此错误发生在启动时,因为您提供的是密码视图控制器。

In order to get rid of this warning, I register the app delegate as a delegate of the navigation root view controller:

为了摆脱这个警告,我将应用程序委托注册为导航根视图控制器的委托:

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ((UINavigationController *)self.window.rootViewController).delegate = self;
    return YES;
}

Then I present the modal view controller in navigationController:didShowViewController:animated:with a dispatch_once:

然后我navigationController:didShowViewController:animated:用一个dispatch_once

- (void) navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        KVPasscodeViewController *passcodeController = [[KVPasscodeViewController alloc] init];
        passcodeController.delegate = self;

        UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:passcodeController];
        [(UIViewController *)self.delegate presentViewController:passcodeNavigationController animated:YES completion:nil];
    });
}

Since navigationController:didShowViewController:animated:is called after the root view controller did appear, the Unbalanced calls to begin/end appearance transitionswarning is gone.

由于navigationController:didShowViewController:animated:在根视图控制器确实出现之后被调用,对开始/结束外观转换警告的不平衡调用消失了。