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

Iphone 对<;开始/结束外观转换的调用不平衡;UINavigationController:0xa98e050>;,iphone,ios,objective-c,ios6,uinavigationcontroller,Iphone,Ios,Objective C,Ios6,Uinavigationcontroller,在编译我得到的代码时 “对的开始/结束外观转换的调用不平衡” 警告 这是我的密码 KVPasscodeViewController *passcodeController = [[KVPasscodeViewController alloc] init]; passcodeController.delegate = self; UINavigationController *passcodeNavigationController = [[UINavigationController allo

在编译我得到的代码时

“对
的开始/结束外观转换的调用不平衡”

警告

这是我的密码

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

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

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

无论如何,我认为,这是当前的ModalViewController问题,设置动画:否,可能会解决您的问题

[(UIViewController *)self.delegate presentModalViewController:passcodeNavigationController animated:NO];
其他选项是:

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

NSTimer
并在0.50到1秒之间调用上述代码。这也是一个有用的技巧。因此,您的pervious viewController已完成其动画

现代解决方案可能是:

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];
});

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

首先,问题没有说明调用新的
viewController
的位置。
我怀疑这是从
-(void)viewDidLoad

将相应的代码移动到
-(void)viewdide出现:
,问题就会消失

这是因为在
-viewDidLoad
,视图已加载,但尚未显示,动画和视图尚未完成

如果您的意图是推送窗户,请在窗户呈现并喷漆后再推


如果您发现自己使用计时器来控制系统行为,请自问您做错了什么,或者您如何才能更正确地执行此操作。

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

为了消除此警告,我将应用程序委托注册为导航根视图控制器的委托:

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
((UINavigationController*)self.window.rootViewController.delegate=self;
返回YES;
}
然后,我在
navigationController:didShowViewController:animated:
中使用
dispatch\u一次显示模式视图控制器

-(void)导航控制器:(UINavigationController*)导航控制器didShowViewController:(UIViewController*)视图控制器动画:(BOOL)动画
{
静态调度一次\u t一次;
发送一次(&U)^{
KVPasscodeViewController*passcodeController=[[KVPasscodeViewController alloc]init];
passcodeController.delegate=self;
UINavigationController*passcodeNavigationController=[[UINavigationController alloc]initWithRootViewController:passcodeController];
[(UIViewController*)self.delegate presentViewController:passcodeNavigationController动画:是完成:无];
});
}

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

在完成之前包含的视图控制器的动画制作之前尝试加载新的视图控制器时,会出现此警告。如果您打算这样做,只需将代码添加到
dispatch\u async(dispatch\u get\u main\u queue()
块:

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

警告就会消失。

是的,我试图引入计时器;我只是认为这是一个黑客行为,但如果这是公认的解决方案……我担心我的代码中有一些根本错误,即,我没有按照众所周知的苹果方式来做,因此出现了错误。安德烈亚斯。如果“有很多其他更好的方式”那你为什么不在这里指定它们呢?因为你的评论是没有建设性的。这对我来说是正确的答案,也简单地解释了发生的事情。在上一个视图的动画完成之前,我做了同样的事情,并以模式方式呈现了一个视图。@Mark Travis:在我的情况下,我不能从“ViewDidAppease”调用。我是using ContainerViewClass并根据某些操作切换视图控制器。此警告消息总是出现。这是正确的解决方案,甚至在至少一个Apple演示中发现需要此解决方案,即MyImagePicker,错误消息ViewController会导致此警告。我确实在
viewDidLoad
a中调用了它nd将代码移动到
视图中,解决了这个问题。这是正确的答案。使用Xcode 9.1和swift 4以及storyboardless项目(我以编程方式完成所有工作)我甚至在从ViewDidAppease提供viewController时也遇到了这个问题。通过在async block DispatchQueue.main.asyncAfter(截止日期:when){}中插入提供的控制器ViewDidLoad的代码,解决了这个问题。