ios 不断收到“<ViewController> 开始/结束外观转换的不平衡调用”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20919616/
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
Keep getting "Unbalanced calls to begin/end appearance transitions for <ViewController>" error
提问by user3117509
I have an app that is almostrunning perfectly. Here is how my app is structured:
我有一个几乎完美运行的应用程序。以下是我的应用程序的结构:
6 total View Controllers on the storyboard. The first 3 View Controllers are the most important. The initial View Controller has buttons to "Login" and "Signup". The "Login" button modally presents a Login View Controller and the "Signup" button modally presents a Signup View Controller.
故事板上共有 6 个视图控制器。前 3 个视图控制器是最重要的。初始视图控制器具有“登录”和“注册”按钮。“登录”按钮以模态方式呈现登录视图控制器,而“注册”按钮以模态方式呈现注册视图控制器。
The Signup View Controller has 3 fields for username, password, and email and then a "submit" button. The submit button submits the data to my web server and if everything submits successfully it calls the "performSegueWithIdentifier" method on itself.
注册视图控制器有 3 个字段用于用户名、密码和电子邮件,然后是一个“提交”按钮。提交按钮将数据提交到我的 Web 服务器,如果一切都成功提交,它会自行调用“performSegueWithIdentifier”方法。
Here is the statement:
这是声明:
[self performSegueWithIdentifier:@"superSegue" sender:self];
I spent 2 hours tonight trying to get the above method call to work and it finally does work. To get it to work, I had to select my Signup View Controller on the storyboard and go to Editor > Embed In > Navigation Controller (If I remember correctly I had to do this because the signup view controller is presented modally). I then dragged from my Signup View Controller's submit button to the View Controller I want to push to and selected Push and then typed in an identifier name.
今晚我花了 2 个小时试图让上述方法调用起作用,它终于起作用了。为了让它工作,我必须在情节提要上选择我的注册视图控制器,然后转到编辑器 > 嵌入 > 导航控制器(如果我没记错的话,我必须这样做,因为注册视图控制器是模态呈现的)。然后我从我的注册视图控制器的提交按钮拖到我想要推送到的视图控制器并选择推送,然后输入标识符名称。
Anyways, all of the above works perfectly fine until I try to use the back button on the View Controller that we pushed to using the method call. If I tap the back button, it goes to a 90% black screen with a blank nav bar at the top with a back button and of course that back button does nothing as well.
无论如何,在我尝试使用我们使用方法调用推送到的视图控制器上的后退按钮之前,上述所有内容都可以正常工作。如果我点击后退按钮,它会进入 90% 的黑色屏幕,顶部有一个空白导航栏和一个后退按钮,当然后退按钮也没有任何作用。
This is the error that I get in the console:
这是我在控制台中得到的错误:
Unbalanced calls to begin/end appearance transitions for <VerificationViewController: 0x14ed1bb0>
Verification View Controller is the View Controller that the Signup View Controller pushes to via the performSegueWithIdentifier method.
验证视图控制器是注册视图控制器通过 performSegueWithIdentifier 方法推送到的视图控制器。
Does anyone know how I can fix this error?
有谁知道我该如何解决这个错误?
I have included a screenshot below of what my storyboard looks like in xcode. There is a view controller that I have coded but not connected yet and shouldn't make a difference anyways so you can ignore the View Controller to the right of the Login VC.
我在下面包含了我的故事板在 xcode 中的样子的屏幕截图。有一个我已经编码但尚未连接的视图控制器,无论如何都不应该有所作为,因此您可以忽略登录 VC 右侧的视图控制器。
采纳答案by user3117509
I found the answer this morning in another stackoverflow question. The answer can be found here.
我今天早上在另一个 stackoverflow 问题中找到了答案。答案可以在这里找到。
When I had originally setup the Push Segue, I clicked on and dragged from a button, and was also calling the performSegueWIthIdentifier method inside that button's IBAction method implementation. This was causing 2 identical push segues to be executed on the button press. I just left my method call in the IBAction, deleted the old push segue, and created a new push segue only this time I clicked on and dragged from the entire View Controller instead of it's button.
当我最初设置 Push Segue 时,我单击并从一个按钮拖动,并且还在该按钮的 IBAction 方法实现中调用 performSegueWIthIdentifier 方法。这导致在按下按钮时执行 2 个相同的 push segue。我只是在 IBAction 中保留了我的方法调用,删除了旧的 push segue,并且仅在这次我单击并从整个 View Controller 而不是它的按钮拖动时创建了一个新的 push segue。
回答by CodeOverRide
I solved this issue by wrapping in this.
我通过包装解决了这个问题。
dispatch_async(dispatch_get_main_queue()) {
//call your performSegueWithIdentifier in here
}
回答by user3099609
In my case it was a subclass of UITabBarController
with an overloaded setSelectedIndex:
method that does the transition with an animation.
I found that the following needs to be called before the animation start:
在我的例子中,它是一个UITabBarController
带有重载setSelectedIndex:
方法的子类,它使用动画进行过渡。我发现在动画开始之前需要调用以下内容:
[sourceVC viewWillDisappear:YES];
[destinationVC viewWillAppear:YES];
And the following in the completion block:
以及完成块中的以下内容:
if (finished) {
[sourceVC viewDidDisappear:YES];
[destinationVC viewDidAppear:YES];
[super setSelectedIndex:selectedIndex];
}
The problem might still occur if multiple selectedIndex changes happen before animations end.
如果在动画结束之前发生多个 selectedIndex 更改,则可能仍会出现该问题。
回答by slobodans
In my case this warning was caused by calling popToRootViewController
of UINavigationController while modal view was displayed.
When i moved popToRootViewController
after modal view dismissed, warning stop to appear.
在我的情况下,此警告是由popToRootViewController
显示模式视图时调用UINavigationController引起的。当我popToRootViewController
在模态视图关闭后移动时,警告停止出现。
回答by foram
Reason For Error: This message get displayed if you are pushing/presenting another View controller from viewWillAppear,loadView,init or viewDidLoad method of current View Controller
错误原因:如果您从当前视图控制器的 viewWillAppear、loadView、init 或 viewDidLoad 方法推送/呈现另一个视图控制器,则会显示此消息
Solution: Move your pushing/presenting code to viewDidAppear method will solve the issue
解决方案:将您的推送/呈现代码移动到 viewDidAppear 方法将解决该问题
The reason is : in viewDidLoad not all of the fancy animations have already been finished, whereas in viewDidAppear everything's done.
原因是:在 viewDidLoad 中并不是所有的花哨动画都已经完成,而在 viewDidAppear 中一切都完成了。
回答by anh hoang
I worked it and it is good for me
Reason For Error : This message get displayed if you are pushing/presenting another View controller from TabBarController,
Solution : please set viewController.modalPresentationStyle = .overCurrentContext
, then present viewController
topViewController.present(vc, animated: true, completion: nil)
我工作了,它对我有好处 错误原因:如果您从 TabBarController 推送/呈现另一个视图控制器,则会显示此消息,解决方案:请设置viewController.modalPresentationStyle = .overCurrentContext
,然后呈现viewController
topViewController.present(vc, animated: true, completion: nil)