ios <UITabBarController: 0x197870> 开始/结束外观转换的不平衡调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7886096/
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
Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x197870>
提问by Raptor
I read SO about another user encountering similar error, but this error is in different case.
我读了关于另一个用户遇到类似错误的信息,但这个错误是在不同的情况下。
I received this message when I added a View Controller initially:
我最初添加视图控制器时收到此消息:
Unbalanced calls to begin/end appearance transitions for
<UITabBarController: 0x197870>
The structure of the app is as follow:
该应用程序的结构如下:
I got a 5-tab TabBarController linked to 5 View Controllers. In the initial showing tab, I call out a new View Controller to overlay as an introduction of the app.
我有一个链接到 5 个视图控制器的 5 选项卡 TabBarController。在最初的显示选项卡中,我调用了一个新的视图控制器来覆盖作为应用程序的介绍。
I use this code to call the introduction view controller:
我使用此代码调用介绍视图控制器:
IntroVC *vc = [[IntroVC alloc] init];
[self presentModalViewController:vc animated:YES];
[vc release];
After this IntroVC
view controller shows up, the above error shows.
此IntroVC
视图控制器出现后,显示上述错误。
p.s. I am using xCode 4.2 & iOS 5.0 SDK, developing iOS 4.3 app.
ps 我正在使用 xCode 4.2 & iOS 5.0 SDK,开发 iOS 4.3 应用程序。
采纳答案by Jesper
Without seeing more of the surrounding code I can't give a definite answer, but I have two theories.
在没有看到更多周围代码的情况下,我无法给出明确的答案,但我有两个理论。
You're not using
UIViewController
's designated initializerinitWithNibName:bundle:
. Try using it instead of justinit
.Also,
self
may be one of the tab bar controller's view controllers. Always present view controllers from the topmost view controller, which means in this case ask the tab bar controller to present the overlay view controller on behalf of the view controller. You can still keep any callback delegates to the real view controller, but you must have the tab bar controller present and dismiss.
您没有使用
UIViewController
的指定初始值设定项initWithNibName:bundle:
。尝试使用它而不仅仅是init
.此外,
self
可能是标签栏控制器的视图控制器之一。始终从最顶层的视图控制器呈现视图控制器,这意味着在这种情况下,要求标签栏控制器代表视图控制器呈现覆盖视图控制器。您仍然可以将任何回调委托保留给真实的视图控制器,但您必须让标签栏控制器存在并关闭。
回答by PokerIncome.com
I fixed this error by changing animated from YES to NO.
我通过将动画从 YES 更改为 NO 来修复此错误。
From:
从:
[tabBarController presentModalViewController:viewController animated:YES];
To:
到:
[tabBarController presentModalViewController:viewController animated:NO];
回答by Peter Lapisu
As posted by danh
You can generate this warning by presenting the modal vc before the app is done initializing. i.e. Start a tabbed application template app and present a modal vc on top of self.tabBarController as the last line in application:didFinishLaunching. Warning appears. Solution: let the stack unwind first, present the modal vc in another method, invoked with a performSelector withDelay:0.0
您可以通过在应用程序完成初始化之前呈现模态 vc 来生成此警告。即启动一个选项卡式应用程序模板应用程序并在 self.tabBarController 顶部呈现一个模态 vc 作为 application:didFinishLaunching 中的最后一行。出现警告。解决方案:先让栈展开,在另一个方法中呈现模态vc,用一个performSelector withDelay:0.0调用
Try to move the method into the viewWillAppear and guard it so it does get executed just once (would recommend setting up a property)
尝试将该方法移动到 viewWillAppear 并保护它,以便它只执行一次(建议设置一个属性)
回答by mllm
Another solution for many cases is to make sure that the transition between UIViewController
s happens afterthe not-suitable (like during initialization) procedure finishes, by doing:
许多情况下的另一个解决方案是通过执行以下操作来确保UIViewController
s之间的转换发生在不合适(如在初始化期间)过程完成之后:
__weak MyViewController *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf presentViewController:vc animated:YES];
});
This is general for also pushViewController:animated:
, etc.
这对于 alsopushViewController:animated:
等是通用的。
回答by Alex Cio
I had the same problem. I called a method inside viewDidLoad
inside my first UIViewController
我有同样的问题。我viewDidLoad
在我的第一个内部调用了一个方法UIViewController
- (void)viewDidLoad{
[super viewDidLoad];
[self performSelector:@selector(loadingView)
withObject:nil afterDelay:0.5];
}
- (void)loadingView{
[self performSegueWithIdentifier:@"loadedData" sender:self];
}
Inside the second UIViewController
I did the same also with 0.5 seconds delay. After changing the delay to a higher value, it worked fine. It's like the segue can't be performed too fast after another segue.
在第二秒内,UIViewController
我也做了同样的事情,延迟了 0.5 秒。将延迟更改为更高的值后,它工作正常。就好像转场不能在另一个转场之后执行得太快。
回答by Tolusha
I had the same problem when I need to Present My Login View Controller from another View Controller If the the User is't authorized, I did it in ViewDidLoad Method of my Another View Controller ( if not authorized -> presentModalViewController ). When I start to make it in ViewDidAppear method, I solved this problem. I Think that ViewDidLoad only initialize properties and after that the actual showing view algorithm begins! Thats why you must use viewDidAppear method to make modal transitions!
当我需要从另一个视图控制器呈现我的登录视图控制器时,我遇到了同样的问题 当我开始在 ViewDidAppear 方法中制作它时,我解决了这个问题。我认为 ViewDidLoad 只初始化属性,然后实际显示视图算法开始!这就是为什么你必须使用 viewDidAppear 方法来进行模态转换!
回答by Adriano Spadoni
I had this problem because of a typo:
由于打字错误,我遇到了这个问题:
override func viewDidAppear(animated: Bool) {
super.viewWillAppear(animated)
instead of
代替
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
It was calling "WillAppear" in the super instead of "DidAppear"
它在超级中调用“WillAppear”而不是“DidAppear”
回答by Kof
If you're using transitioningDelegate
(not the case in this question's example), also set modalPresentationStyle
to .Custom
.
如果您正在使用transitioningDelegate
(在这个问题的示例中不是这种情况),也设置modalPresentationStyle
为.Custom
.
Swift
迅速
let vc = storyboard.instantiateViewControllerWithIdentifier("...")
vc.transitioningDelegate = self
vc.modalPresentationStyle = .Custom
回答by pankesh
I solved it by writing
我通过写作解决了它
[self.navigationController presentViewController:viewController
animated:TRUE
completion:NULL];
回答by J. Lopes
I had this problem with a third party code. Someone forgot to set the super inside of viewWillAppear and viewWillDisappear in a custom TabBarController class.
我在使用第三方代码时遇到了这个问题。有人忘记在自定义 TabBarController 类中设置 viewWillAppear 和 viewWillDisappear 中的 super 。
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// code...
}
or
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// code...
}