<UITabBarController: 0x197870>的开始/结束出现转换调用不平衡。

133

我在SO上阅读到另一个用户遇到类似的错误,但这个错误和那个不同。

当我最初添加一个视图控制器时,我收到了这个消息:

Unbalanced calls to begin/end appearance transitions for 
<UITabBarController: 0x197870>

应用程序的结构如下:

我使用了一个包含5个视图控制器的标签栏控制器。在初始显示标签中,我调用一个新的视图控制器作为应用程序的介绍。

我使用以下代码来调用介绍视图控制器:

IntroVC *vc = [[IntroVC alloc] init];
[self presentModalViewController:vc animated:YES];
[vc release]; 

在这个IntroVC视图控制器显示之后,出现了上述错误。

p.s. 我正在使用xCode 4.2&iOS 5.0 SDK,开发iOS 4.3应用程序。


嗨,Shivan,我和你有同样的问题。但是在查看下面的答案后,我仍然无法解决它。请问你在哪里调用了介绍视图控制器? - ZYiOS
24个回答

0
如@danh所建议的那样,我的问题在于我在UITabBarController准备好之前就已经展示了模态视图控制器。然而,我不太放心使用一个固定的延迟来展示视图控制器(根据我的测试,我需要使用0.05-0.1s延迟的performSelector:withDelay:)。我的解决方案是添加一个在UITabBarControllerviewDidAppear:方法中调用的块:

PRTabBarController.h:

@interface PRTabBarController : UITabBarController

@property (nonatomic, copy) void (^viewDidAppearBlock)(BOOL animated);

@end

PRTabBarController.m:

#import "PRTabBarController.h"

@implementation PRTabBarController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (self.viewDidAppearBlock) {
        self.viewDidAppearBlock(animated);
    }
}

@end

现在在application:didFinishLaunchingWithOptions:方法中

PRTabBarController *tabBarController = [[PRTabBarController alloc] init];

// UIWindow initialization, etc.

__weak typeof(tabBarController) weakTabBarController = tabBarController;
tabBarController.viewDidAppearBlock = ^(BOOL animated) {
    MyViewController *viewController = [MyViewController new];
    viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [weakTabBarController.tabBarController presentViewController:navigationController animated:NO completion:nil];
    weakTabBarController.viewDidAppearBlock = nil;
};

-1

当我将一个UIButton连接到故事板中的segue操作(在IB中)时,遇到了这个错误,但后来决定让按钮通过编程方式调用performSegueWithIdentifier,忘记从IB中删除第一个。

本质上它执行了两次segue调用,导致此错误并实际上将我的视图推了两次。解决方法是删除其中一个segue调用。

希望这能帮助像我一样疲惫不堪的人!


-1
我在从根TVC导航到TVC A,然后再到TVC B时遇到了这个问题。在TVC B中点击“加载”按钮后,我想直接跳回根TVC(没有必要再访问TVC A,为什么要这样做呢)。我的代码是这样的:
//Pop child from the nav controller
[self.navigationController popViewControllerAnimated:YES];
//Pop self to return to root
[self.navigationController popViewControllerAnimated:YES];

...出现了“未平衡的调用begin/end等”错误。以下修复了该错误,但没有动画:

//Pop child from the nav controller
[self.navigationController popViewControllerAnimated:NO];
//Then pop self to return to root
[self.navigationController popViewControllerAnimated:NO];

这是我的最终解决方案,没有错误且仍然具有动画效果:

//Pop child from the nav controller
[self.navigationController popViewControllerAnimated:NO];
//Then pop self to return to root, only works if first pop above is *not* animated
[self.navigationController popViewControllerAnimated:YES];

-1

Swift 5

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {


//Delete or comment the below lines on your SceneDelegate.

//        guard let windowScene = (scene as? UIWindowScene) else { return }
//        window?.windowScene = windowScene
//        window?.makeKeyAndVisible()

        let viewController = ListVC()
        let navViewController = UINavigationController(rootViewController: viewController)
        window?.rootViewController = navViewController

    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接